in reply to A two-liner for Backtracking for substitutions
in thread Backtracking for substitutions
Many people (including yours truly at one time), mistakenly assume that \w does not match 0-9. Surprise! It does. This caused me a problem when I was trying to do the following:[\w\d]
It failed pretty quickly because $type was getting set to product123 (it didn't pick up the "4" because \d had to match something).my $text = "product1234imageSmall.jpg"; ($type, $id, $property) = ($1, $2, $3) if $text =~ /^(\w+)(\d+)(\w+)/;
In this case, because you are including both \w and \d in a character class, there's only an issue of redundancy and doesn't affect the functioning of the regex. I just wanted to point this out because it's easy to miss that and get bitten in other situations.
Cheers,
Ovid
Join the Perlmonks Setiathome Group or just go the the link and check out our stats.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: (Ovid - Common regex error) RE: A two-liner for Backtracking for substitutions
by markwild (Sexton) on Oct 03, 2000 at 02:44 UTC | |
by Ovid (Cardinal) on Oct 03, 2000 at 03:10 UTC |