Re: regexps [was: aterm] - off-topic, wot

Andre Pang (
Thu, 15 Apr 1999 01:02:03 +1000

On Wed, Apr 14, 1999 at 09:46:09AM -0400, Simon Drabble wrote:

> > Does anyone have a regular expression that would identify this:
> > [+|-]digit
> > Testing for a digit or a leading + or - is easy, but I can't 
> > come up with a regular expression that will identify a string
> > as a digit that may or may not have a leading plus or minus sign.
> > Thanks.
> Try:
> (([+-][0-9]+)|([0-9]+))

    If your regular expression engine doesn't support +'s and |'s (eg some
versions of grep), try:


> If you were testing whether a string is _only_ a number (i.e. does not
> contain alpha or punct characters other than `.') then you could put a $
> at the end of the above regexp. - testing for fp's would be easier then

    You'd also need to put a ^ at the beginning as well as a $ at the end..

    Or for a slightly more versatile regexp which picks up floating point
numbers as well as standard boring integers:


    (Thanks to CaT for helping me figure that one out!).

    - #ozone