in reply to Help with regular expression
As you can see, your regex matched foobar 42 but did not match foobar 422, which appears to be what you want.DB<4> $_ = 'foobar 42'; DB<5> print $1 if /\b(\s*([a-zA-Z ]+)\s((-?[0-9]){1,2})\b)/g; foobar 42 DB<6> $_ = 'foobar 666'; DB<7> print $1 if /\b(\s*([a-zA-Z ]+)\s((-?[0-9]){1,2})\b)/g; DB<8>
If that is not what you want, then you should explain what exactly you want, and preferably, as already suggested, please also show some example of what should match (and what should be captured) and what should not match.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Help with regular expression
by heman (Novice) on Nov 13, 2014 at 01:20 UTC | |
by toolic (Bishop) on Nov 13, 2014 at 01:45 UTC | |
by heman (Novice) on Nov 13, 2014 at 02:42 UTC | |
by graff (Chancellor) on Nov 13, 2014 at 02:26 UTC |