Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Regular Expression help 1

Status
Not open for further replies.

Laeg

Programmer
Nov 29, 2004
95
IE
Can I get some help with a regular expression? I'm trying to express the following for a string

Up to 4 digits, but the first digit must be a 0 followed by a hyphen followed by up to 7 digits. So the following are examples of valid strings

02-456
0546-456789

Thanks

 
Hi

Laeg said:
Up to 4 digits, but the first digit must be a 0 followed by a hyphen followed by up to 7 digits.
Let us rephrase it as a '0' character followed by up to 0..3 digits, followed by a hyphen, followed by up to 0..7 digits. Because you not specified the lower limit for those "up to" ;-) :
Code:
/^0[[:digit:]]{0,3}-[[:digit:]]{0,7}$
Just adjust the lower limits of the quantifiers if needed.


Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top