I'm porting some Lua code to JS and I haven't worked with Lua so far.
There's the Lua pattern "^([^aeiouàèéêíòóôúïü]*)(.-)$" and I found the following explanation for the hyphen here:
- Match the previous character (or class) zero or more times, as few times as possible.
I'm trying to figure out what the equivalent as a regular expression would be. Also I don't understand why this is needed in the first place - wouldn't ending in (.*)$ suffice?
In Java, .- is actually equivalent of [\s\S]*? or (?s).*?, or - to play it safe - (?s:.*?), because . in Lua patterns matches any char (including line break chars) and - is the lazy (non-greedy) quantifier that matches 0 or more chars, i.e. *? in regular NFA regex.
See Lua patterns:
. all characters
And then
The
`+´modifier matches one or more characters of the original class. It will always get the longest sequence that matches the pattern.
The modifier`*´is similar to`+´, but it also accepts zero occurrences of characters of the class...
Like`*´, the modifier`-´also matches zero or more occurrences of characters of the original class. However, instead of matching the longest sequence, it matches the shortest one.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With