in reply to Regex help needed
print "$+{first} $+{last}\n" if m/^ (?<last> [^%]+ ) % (?<first> [^%]+ ) % (?<id> A [^%]+ ) /x;
Really, the critical component is to use a negated character class to match anythig that is not the delimiter, rather than relying on non-greedy specifications.
If your Perl is old enough to not have named captures, this is equivilent code that is more universally compatible:
print "$2 $1\n" if m/^([^%]+)%([^%]+)%(A[^%]+)/;
Update: Added /x and nicer formatting.
Dave
|
|---|