Hi Gabor, It looks great (especially the last one), but assuming I have just few components, and the text is big, I guess that restarting regex engine few times for the same string is a waste of performance, am I right ? I guess study() can help here, but I remember reading in the past that it’s not a good practice to use it.
Yossi From: Perl [mailto:[email protected]] On Behalf Of Gabor Szabo Sent: Thursday, August 28, 2014 9:52 AM To: Perl in Israel Subject: Re: [Israel.pm] regex question: When order doesn't matter On Thu, Aug 28, 2014 at 9:28 AM, Yossi Itzkovich <[email protected]<mailto:[email protected]>> wrote: Hi, Sometime I want to find a line that contains 2+ patterns components, but I don’t mind the order of the components in the line. The naïve approach is to do one of the following code options 1. /a.+?b/ or /b.+?a/ 2. /(?:a.+?b)|(?:b.+?a)/ (this one probably is more efficient) But I don’t feel comfortable with any of the above (and when there are more than 2 components it gets worse). Is there a better way of doing it ? if (/a/ and /b/) { } and if you have more regexs all of them in @regexes then my @regexes = (qr/a/, qr/b/, qr/c/); use List::MoreUtils qw(all); if (all { /$_/ } @regexes) { } Gabor
_______________________________________________ Perl mailing list [email protected] http://mail.perl.org.il/mailman/listinfo/perl
