regex.lua 1.6 KB

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