in reply to Set theory in regexs
This problem must be solved with a regex (for other reasons).Because it means you are artificially restricting the implementation to something that doesn't work well, except when you are toying with the language instead of doing real work with it. Often the case with doing homework, but I won't go that far to accuse you of doing a homework problem using the resources of the monestary. {grin}
The problem you ask is not solved well by a regex. Certainly, you can see if a string has both "d4" and "b2" in it using two forward lookaheads:
But this is not particularly efficient, nor will any solution be efficient if you restrict your implementation to "must be solved with a regex".my $good = $string =~ /^(?=.*?(\s|^)d4(\s|$))(?=.*?(\s|^)b2(\s|$))/;
Please explain the need for a regex.
-- Randal L. Schwartz, Perl hacker
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: Re: Set theory in regexs
by dcorbin (Sexton) on Sep 02, 2000 at 21:16 UTC |