Accidentally responded to originator, not list: ----- Forwarded message from [EMAIL PROTECTED] -----
On 14 Feb 02 at 10:25:13PM, Daniel R. Allen wrote: > Thanks to all of the people who came up with answers. Ultimately the one > I'm happiest with was the one Japhy emailed me, which shows that it can > indeed be done in a regex. Well, I think that's stretching it a bit. It's doing it with a "while" loop that uses a regex among other operations. Mind you, you can't really do much with just a regex; you generally need m//xyz or s///xyz or split, at least, and often control structures to provide repeated matching. People often ask "can you give me a regex to do <blah>", when they mean "can you give me a substitution statement to do <blah>" or more cynically, "I don't know much about Perl, but I've heard Perl regexes can do everything...". -- DRA previously: > As I understand, perl uses the Boyer-Moore algorithm in the regex > engine, so should it be possible to backtrack to the longest common > string using a RE? Even if you don't know the text of the match > beforehand? I'm not sure what this has to do with B-M...I thought that was simply an efficient algorithm for matching a specific substring. Backtracking is a property of the matching engine. None of the solutions are specifically using B-M to achieve the effect you were after; but some use external code to work around the limitations of the regex engine, one of which, it could be argued I suppose, being that the regex engine can only match against a single string... --- I was curious to see what Japhy would do to join the strings (to allow the regex engine to attack both together). I ended up shying away from joining them, partly to avoid false matches (Japhy has ruled them out by disallowing NULs), and partly because I thought it was simpler to just do a plain string match using index() on the second string (which I seem to remember reading uses B-M in its implementation...). > And it even works in perl 5.005. That's the shame about experimental features ("(?{})", which I used to gain access to all the substrings to avoid the while loop, did not work as well in earlier versions). Regards, Ian ----- End forwarded message -----