Re: Extract alternate patterns
- From: Ben Bacarisse <spam@xxxxxxxxx>
- Date: 17 Jul 2006 14:29:45 GMT
harsha.ramanagoudra@xxxxxxxxx wrote:
Hi all,<snip>
I am trying to extract alternate patterns in strings. The difficulty
is because of optional patterns.
if($transaction =~ /(addReq|modReq|subtractReq)+?.*?(addReq)?/){<snip>
print "$1..$2\n";
}
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.
.
- References:
- Extract alternate patterns
- From: harsha . ramanagoudra
- Extract alternate patterns
- Prev by Date: Re: Extract alternate patterns
- Next by Date: Re: Perl equivalent of this script?
- Previous by thread: Re: Extract alternate patterns
- Next by thread: A subroutine for gcd
- Index(es):
Relevant Pages
|