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

Henning Percy (
Wed, 14 Apr 1999 16:33:56 +0100 (BST)

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:


	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:


	This would match the following:


	But would not match this:


	Hope this helps.