Regular Expressions for the JavaScript target.
Example:
import std/jsre let jsregex: RegExp = newRegExp(r"\s+", r"i") jsregex.compile(r"\w+", r"i") assert "nim javascript".contains jsregex assert jsregex.exec(r"nim javascript") == @["nim".cstring] assert jsregex.toCstring() == r"/\w+/i" jsregex.compile(r"[0-9]", r"i") assert "0123456789abcd".contains jsregex assert $jsregex == "/[0-9]/i" jsregex.compile(r"abc", r"i") assert "abcd".startsWith jsregex assert "dabc".endsWith jsregex jsregex.compile(r"\d", r"i") assert "do1ne".split(jsregex) == @["do".cstring, "ne".cstring] jsregex.compile(r"[lw]", r"i") assert "hello world".replace(jsregex,"X") == "heXlo world" jsregex.compile(r"([a-z])\1*", r"g") assert "abbcccdddd".replace(jsregex, proc (m: varargs[cstring]): cstring = ($m[0] & $(m.len)).cstring) == "a1b2c3d4" let digitsRegex: RegExp = newRegExp(r"\d") assert "foo".match(digitsRegex) == @[]
Types
RegExp = ref object of JsRoot flags*: cstring ## cstring that contains the flags of the RegExp object. dotAll*: bool ## Whether `.` matches newlines or not. global*: bool ## Whether to test against all possible matches in a string, or only against the first. ignoreCase*: bool ## Whether to ignore case while attempting a match in a string. multiline*: bool ## Whether to search in strings across multiple lines. source*: cstring ## The text of the pattern. sticky*: bool ## Whether the search is sticky. unicode*: bool ## Whether Unicode features are enabled. lastIndex*: cint ## Index at which to start the next match (read/write property). input*: cstring ## Read-only and modified on successful match. lastMatch*: cstring ## Ditto. lastParen*: cstring ## Ditto. leftContext*: cstring ## Ditto. rightContext*: cstring ## Ditto. hasIndices*: bool ## https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/hasIndices
- Regular Expressions for JavaScript target. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp Source Edit