in reply to pull out num from str
First of all, a character class already means "one of these characters", so your pipe isn't doing what you think it is. It would match |123. So that should be [+-]. It's also not necessary to escape the plus sign within a character class. Then, to say "zero or one of these," append ? to it, giving you [+-]? . You can also drop the .* from the beginning and .*$ from the end, since they're implied anyway. That gets your regex down to /([+-]?\d+)/ .
Aaron B.
My Woefully Neglected Blog, where I occasionally mention Perl.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: pull out num from str
by jwkrahn (Abbot) on Apr 23, 2012 at 08:45 UTC | |
|
Re^2: pull out num from str
by icoder (Novice) on Apr 23, 2012 at 09:14 UTC | |
|
Re^2: pull out num from str
by icoder (Novice) on Apr 23, 2012 at 11:55 UTC | |
by aaron_baugher (Curate) on Apr 23, 2012 at 17:01 UTC |