Skip to content

Commit a7344e3

Browse files
committed
docs: luau add addl info about string functions using pattern matching by default
1 parent 771fb5f commit a7344e3

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/cmd/luau.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,28 @@ Some examples:
6060
$ qsv luau filter "tonumber(a) > 45"
6161
$ qsv luau filter "tonumber(a) >= tonumber(b)"
6262
63+
PATTERN MATCHING WITH string.find AND OTHER STRING FUNCTIONS:
64+
Lua/Luau string functions like string.find, string.match, string.gsub use
65+
PATTERN MATCHING by default, where certain characters have special meanings:
66+
( ) . % + - * ? [ ] ^ $
67+
68+
If you need to search for these characters literally, you have two options:
69+
70+
1. Escape special characters with % (percent sign):
71+
$ qsv luau filter "string.find(Name, 'John %(Jr%)')"
72+
$ qsv luau map dots "string.gsub(col.text, '%%.', '')"
73+
74+
2. Use plain text mode (4th parameter = true):
75+
$ qsv luau filter "string.find(Name, 'John (Jr)', 1, true)"
76+
$ qsv luau map match "string.find(col.text, 'Mr.', 1, true)"
77+
78+
Common gotchas:
79+
- Parentheses in names like "Jane (Smith)" need escaping or plain mode
80+
- Dots in email addresses, URLs, or decimal numbers
81+
- Hyphens in phone numbers or dates
82+
83+
For more on Lua patterns: https://www.lua.org/manual/5.4/manual.html#6.4.1
84+
6385
Typing long scripts on the command line gets tiresome rather quickly. Use the
6486
"file:" prefix or the ".lua/.luau" file extension to read non-trivial scripts
6587
from the filesystem.

0 commit comments

Comments
 (0)