The regex x{m, n}
matches from m
to n
repetitions of the preceding x
, attempting to match as many as possible.
I have a naive solution, but the number of nodes and edges depends on m
and n
, which is unacceptable when n
is big.
So, is there any effective way to convert the regex to NFA ?
Unfortunately, NFAs don't "count" very well. You're essentially going to have to manually expand your regex to something Thompsons' construction can handle. eg
m{2,5} -> mm(m(m(m)?)?)?
Search for the function SimplifyRepeat
here to see Google's implementation. See this page for more information on regex implementation in practice.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.