luau map question #3091
|
Given cat > a.csv <<EOF
No,Name,Minutes,Points
1,DNE (2),16,1
2,Eberhard Lisse,33,1
EOFqsv luau map newpoints "if string.find(Name,'Eberhard Lisse') then return 0 else return Points end" a.csvreturns No,Name,Minutes,Points,newpoints
1,DNE (2),16,1,1
2,Eberhard Lisse,33,1,0which is what I expected but qsv luau map newpoints "if string.find(Name,'DNE (2)') then return 0 else return Points end" a.csvreturns No,Name,Minutes,Points,newpoints
1,DNE (2),16,1,1
2,Eberhard Lisse,33,1,1which is unexpected. What am I doing wrong? QSV 9.1.0 on Mac Tahoe 26.1 |
Replies: 2 comments 2 replies
|
Hi @ondohotola, You're not doing anything wrong! This is actually expected behavior in Lua/Luau pattern matching. In Lua/Luau,
When you search for If you need to use these reserved characters in
returns the expected result: No,Name,Minutes,Points,newpoints
1,DNE (2),16,1,0
2,Eberhard Lisse,33,1,1Alternatively, you can also use "plain text mode" with
https://www.codecademy.com/resources/docs/lua/strings/find I'm adding some info in the usage text to call this out. |
|
Ah, RTFM. That works. Thanks. |
Hi @ondohotola,
You're not doing anything wrong! This is actually expected behavior in Lua/Luau pattern matching.
In Lua/Luau,
string.finduses pattern matching by default, where certain characters have special meanings:( )- Captures/groups.- Any character%- Escape character[ ]- Character classes*,+,-,?- QuantifiersWhen you search for
'DNE (2)', the parentheses()are interpreted as pattern metacharacters (empty capture groups), not literal parentheses. This changes how the pattern is evaluated, causing the match to fail.If you need to use these reserved characters in
string.find, you need to escape them with a "%" sign. Thus:qsv luau map newpoints "if string.find(Name,'…