Regex help

  • Thread starter Thread starter Stuliet
  • Start date Start date
S

Stuliet

Can anyone suggest how to match the following lines with regex

I have three basic patterns of text
1. A 1-8 digit code eg, 12345678 or 1234
2. A range specification eg, 1234:7890
3. A wilcard specification eg, >1234 or <=45678

So I want to test the following strings to see if they are valid (they all
are);

1234:1456,12345678
<4500,>=60000
123
 
Stuliet said:
Can anyone suggest how to match the following lines with regex

I have three basic patterns of text
1. A 1-8 digit code eg, 12345678 or 1234

^[0-9]{1,8}$
1 to 8 digits (= "0" to "9")

2. A range specification eg, 1234:7890

^[0-9]+:[0-9]+$
number (at least one digit), followed by a :, followed by at least one digit
3. A wilcard specification eg, >1234 or <=45678


So I want to test the following strings to see if they are valid (they all
are);

1234:1456,12345678
<4500,>=60000
123

or combined:

^([0-9]{1,8})|([0-9]+:[0-9]+)|((<|<=|>|>=)[0-9]+)$


Hans Kesting
 
Back
Top