Extract alternate patterns



Hi all,
I am trying to extract alternate patterns in strings. The difficulty
is because of optional patterns.

Below is the code,$transaction is the search string.

if($transaction =~ /(addReq|modReq|subtractReq)+?.*?(addReq)?/){
print "$1..$2\n";
}

The above code is succeeding to match the first pattern but always
fails to match the optional second addReq. 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
subtractReq

Thanks
Harsha

.



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)
  • Re: Extract alternate patterns
    ... I am trying to extract alternate patterns in strings. ... addReq.. ... My intention is that this search extracts patterns like those below. ...
    (comp.lang.perl.misc)