PDA

View Full Version : Regular Expression



Varsuuk
February 14th, 2020, 03:54
Are not my strength ;) beyond the simple ones I use regularly in grep and vi.

Which "flavor" of expressions are used in Lua/FG?
I used to plug in really complex expressions into various online "decomposers" like regexpr.com (forgot exact name) to show graphically what it is doing.

I suspect, glancing at https://riptutorial.com/lua/example/20315/lua-pattern-matching after a search that Lua is not using a "standard" syntax of RE like pcre or grep(not sure which that is) or any of the others.

Figure if it has a name I could search for a translator to save my looking at them char at a time... cos yes, I like to avoid the effort :(

Varsuuk
February 14th, 2020, 04:06
I mean for example if I tried to input

^align%s*%(([^)]+)%)$
on
https://regexper.com/#%5Ealign%25s*%25%28%28%5B%5E%29%5D%2B%29%25%29%24

it would translate it wrong:
31598

Instead of:

<starts with>align<followed by 0..n spaces then>(<then it saves in a "group" 1..n characters until it sees the first>)<which should be the end of the line>
(unsure if that means it would not stop at first ")" if later there was a ")" at end of line..., e.g. align (1)111) -> would that NOT match or match the group as "1)111"? )

Talyn
February 14th, 2020, 04:25
Lua doesn't use regex, it uses it's own "pattern matching" which is nowhere near as comprehensive as regex.

Start here to read up on it (https://www.lua.org/pil/20.2.html) and here for pattern matching functions (https://www.lua.org/pil/20.1.html).

Moon Wizard
February 14th, 2020, 04:28
Lua uses its own pattern matching engine.
https://www.lua.org/pil/20.2.html

Here’s why:
https://stackoverflow.com/questions/6192137/how-to-write-this-regular-expression-in-lua/6192354#6192354

I occasionally look for a pattern tester online; but haven’t found one that I have kept.

Regards,
JPG

Varsuuk
February 14th, 2020, 04:35
Thanks, yeah, I just started looking at the patterns and realized what I thought they said was wrong (used to other regex) so then found some Lua reg expression info and was "oooo, I see..." and hoped there was a good scanner for it to avoid noob mistakes in my interpretations in case I used one of them as basis for new match string later.

I'll just have to be careful then :)