I am trying to make a regular expression but i am newbie in it. And it seems Like i am failing again and again in this..
Kindly if anyone can help me
Basically what i want an expression that tests for the following,
1- Something that starts with abc or def, followed by a number between
0 and 900, then can have anything between that, up until the nearest
!!
Any help will be regarded
Best Regards
If you want this
abcXXX(0<xxx<900)ordefXXX (0<xxx<900)try this:Explanation: The regex
[0-9]matches single-digit numbers 0 to 9.[1-9][0-9]matches double-digit numbers 10 to 99. That’s the easy part. So0-900is0-899and900so REGEX is[0-9]|[1-9][0-9]|[1-8][0-9][0-9]|900. Add\b( )\bis Boundary Matchers. Similar todef: start withdeffollowed by 3 digits.At last use
|isor.Tested with Regular Expression Test Page for Java
Maybe i didn’t try some weird input but this is the basic parts for you to dig by yourself
Edit with Alan Moore’s nicer suggestion :