I am trying to extend a tool that looks at files, searching for certain patterns. The tool is in perl and makes copious use of regular expressions. I came across a new pattern that has me scratching my head. I am trying to match a certain expression e that can have more than one definition ( shown in much simplified form ):
1. e =~ u 2. e =~ uae 3. e =~ edefe 4. e =~ ebe 5. e =~ ec
As you can see, all but the first are recursive matches. I could write the above as
e =~ u|uae|edefe|ebe|ec
Here is what I have so far: if I had only 1 and 2 from above, I could write the combination of 1 and 2 as
e =~ u(?:au)*
Likewise, for 1 and 3, I could write
e =~ udufu
For 1 and 4, I would have
e =~ ubu
and for 1 and 5, I would have
e =~ uc
To go further, I would have to combine more than two together, and I think it could get horrifyingly complex. Is there a way to tackle a problem like this with dynamic regexes, or is there a method for substituting the above together?
I have perl 5.6, so I am slightly limited on what I can do. I do not know dynamic regexes well enough to frame the above with those. I cannot use CPAN or anything other than the screwdriver I have.
In reply to When the only tool you have is a screwdriver... by ExReg
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |