Re

Use regular expressions to search and manipulate strings

As Pointless is currently implemented in JavaScript, it inherits some of the limitations of the UTF-16 encoding that JS uses, for example:

Re.test("", "^.$") -- '.' matches BMP character U+263A
Re.test("😀", "^.$") -- '.' doesn't match SMP character U+1F600
true
false

Module Contents


Re.escape(string)

Escape special characters in string so it can be used as a literal in a regular expression.

Re.escape("Hello? Can you *hear* me??")
"Hello\\? Can you \\*hear\\* me\\?\\?"

Re.match(string, pattern)

Find the matches for pattern in string.

Return a table with the following columns:

  • value: The matched substring.
  • index: Index of value in string.
  • groups: List of captures.
  • named: Object of named captures.
Re.match("nessa@example.com, megan@xkcd.com", r"(?<name>\w+)@(\w+\.\w+)")
panic: unexpected token
type: string
token: "(?<name>\w+)@(\w+\.\w+)"
expected: ,

Re.match("nessa@example.com, megan@xkcd.com", r"(?<name>\w+)@(\w+\.\w+)")
                                               ^
At Re:embedded:1:48

Re.replace(string, pattern, replacement)

Replace all matches of pattern in string with replacement.

Re.replace("2025  07 22", " +", ".")
"2025.07.22"

Re.replaceBy(string, pattern, replacer)

Replace all matches of pattern in string with replacement.

Re.replaceBy("a catalog of cats", r"cat\w*", Str.toUpper)
panic: unexpected token
type: string
token: "cat\w*"
expected: ,

Re.replaceBy("a catalog of cats", r"cat\w*", Str.toUpper)
                                   ^
At Re:embedded:1:36

Re.split(string, pattern)

Split string using the regular expression pattern. The matching separators are not included in the resulting substrings.

Re.split("NYC NY  USA", " +")
["NYC", "NY", "USA"]

Re.test(string, pattern)

Check whether string matches the regular expression pattern.

Re.test("nessa@example.com", r".+@.+\..+")
Re.test("nessa at example dot com", r".+@.+\..+")
panic: unexpected token
type: string
token: ".+@.+\..+"
expected: ,

Re.test("nessa@example.com", r".+@.+\..+")
                              ^
At Re:embedded:1:31