regex.lua (1618B)
1 --- @meta 2 3 -- luacheck: no unused args 4 5 --- @brief Vim regexes can be used directly from Lua. Currently they only allow 6 --- matching within a single line. 7 8 --- Parses the Vim regex `re` and returns a regex object. Regexes are "magic" and case-sensitive by 9 --- default, regardless of 'magic' and 'ignorecase'. They can be controlled with flags, see |/magic| 10 --- and |/ignorecase|. 11 --- @param re string 12 --- @return vim.regex 13 function vim.regex(re) end 14 15 --- @nodoc 16 --- @class vim.regex 17 local regex = {} -- luacheck: no unused 18 19 --- Matches string `str` against this regex. To match the string precisely, surround the regex with 20 --- "^" and "$". Returns the byte indices for the start and end of the match, or `nil` if there is 21 --- no match. Because any integer is "truthy", `regex:match_str()` can be directly used as 22 --- a condition in an if-statement. 23 --- @param str string 24 --- @return integer? # match start (byte index), or `nil` if no match 25 --- @return integer? # match end (byte index), or `nil` if no match 26 function regex:match_str(str) end 27 28 --- Matches line at `line_idx` (zero-based) in buffer `bufnr`. Match is restricted to byte index 29 --- range `start` and `end_` if given, otherwise see |regex:match_str()|. Returned byte indices are 30 --- relative to `start` if given. 31 --- @param bufnr integer 32 --- @param line_idx integer 33 --- @param start? integer 34 --- @param end_? integer 35 --- @return integer? # match start (byte index) relative to `start`, or `nil` if no match 36 --- @return integer? # match end (byte index) relative to `start`, or `nil` if no match 37 function regex:match_line(bufnr, line_idx, start, end_) end