Re: Extract alternate patterns



harsha.ramanagoudra@xxxxxxxxx wrote:
Hi all,
I am trying to extract alternate patterns in strings. The difficulty
is because of optional patterns.
<snip>
if($transaction =~ /(addReq|modReq|subtractReq)+?.*?(addReq)?/){
print "$1..$2\n";
}

<snip>
The output I get is

addReq..

My intention is that this search extracts patterns like those below. In
some cases $2 may be undef

addReq
addReq..addReq
modReq..addReq

The above is matched as three parts:

"modReq" by (addReq|modReq|subtractReq)+
"..addReq" by .*
"" by (addReq)

There are several fixes, but the simplest would be to be more
restrictive than .* in the middle part.

--
Ben.
.



Relevant Pages

  • Re: Extract alternate patterns
    ... I am trying to extract alternate patterns in strings. ... is because of optional patterns. ... Below is the code,$transaction is the search string. ...
    (comp.lang.perl.misc)
  • Extract alternate patterns
    ... I am trying to extract alternate patterns in strings. ... is because of optional patterns. ... Below is the code,$transaction is the search string. ...
    (comp.lang.perl.misc)
  • Re: vintage patterns -- to cut or not?
    ... intention of making the garment. ... Seems vintage uncut patterns can ... I am thinking of tracing the patterns, ...
    (alt.sewing)