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. I'd probably use something like: ([-+]?)([0-9]+) assuming that it's jsut for integers. It breaks down like this: [-+] A plus or minus sign [-+]? Zero or one plus or minus signs That's that leading bit done. [0-9]+ One or more of the characters 0-9. That's the number bit. Put brackets round each part, just to make sure and then join them together gives: ([-+]?)([0-9]+) This would match the following: 1 +12345 -123 But would not match this: ++12312321 --2356 Hope this helps. Adler -----------------------------------=[]=---------------------------------------- -- WWW: http://www.afterstep.org/ FTP: ftp://ftp.afterstep.org/ MAIL: http://www.caldera.com/linuxcenter/forums/afterstep.html