Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!mips!apple!agate!sunkist.berkeley.edu!raymond From: raymond@math.berkeley.edu (Raymond Chen) Newsgroups: comp.lang.perl Subject: Re: pattern1 AND pattern2? Message-ID: <1991Apr25.201644.1546@agate.berkeley.edu> Date: 25 Apr 91 20:16:44 GMT References: <130399@uunet.UU.NET> Sender: root@agate.berkeley.edu (Charlie Root) Reply-To: raymond@math.berkeley.edu (Raymond Chen) Organization: U.C. Berkeley Lines: 40 In-Reply-To: rbj@uunet.UU.NET (Root Boy Jim) Originator: raymond@sunkist.berkeley.edu In article <130399@uunet.UU.NET>, rbj@uunet (Root Boy Jim) writes: >In article dennis@nosc.mil (Dennis Cottel) writes: >?I know how to get a successful match on either of two patterns: >?"/pattern1|pattern2/". How can I say that both have to match? >/pat1/ && /pat2/ && do { &whatever(you,like); }; Although this works, it doesn't set $& properly. Upon further thought, I believe Mr. Cottel was looking for a pattern that produces $& such that $& =~ /^pat1$/ and $& =~ /^pat2$/ Assume for the moment that `&' serves the purpose. Then "Larry is not just another perl hacker" =~ / \S* \S* &.*r.*p.*/ would set $& = " another perl ". The pattern matches `two consecutive space-delimited words such that the letter `r' appears before the letter `p' somewhere in the string'. Now I know this could be done conventionally as / \S*r\S*p\S* \S* | \S*r\S* \S*p\S* | \S* \S*r\S*p\S* / but you can see how it gets more complicated as the combinations get nastier. For example, suppose the pattern were / \S* \S* &[^aeiou]*a[^aeiou]*e[^aeiou]*i[^aeiou]*o[^aeiou]*u[^aeiou]*/ which matches two consecutive words which together use all the vowels in order. For example, it would pull out the third and fourth words from "Do not name pious mermaids Fred." Personally, I'm stumped. -- eval "format=\nJust another perl hacker,\n.";write; # Note that version 3.041 segfaults; insert^\n here to remedy. # I don't have access to 4.x to see if it faults there.