Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to simulate pattern matching quantifiers?

Asked by 2 years ago
Edited 2 years ago

I have noticed that Lua does not support a couple pattern matching quantifiers like:


[]{n1, n2} which would match the preceding set min n1, and max n2 times.
[]{n1} which would match the preceding set exactly n1 times.


Example of use:


local str = "0000.0000.0000.0000.0000" -- an example ID
local pattern = "(([%d]{4}[.]*){5})"
local match = str:match(pattern) -- should be able to match the 'ID'

I understand that in this example, I could take the string to get the 'ID', but If it were to be located in more complex surroundings, like a giant string, I would have to use pattern matching to find it.

Is there a way to simulate a similar behavior?

Answer this question