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.
In reply to Re: pull out num from str
by aaron_baugher
in thread pull out num from str
by icoder
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |