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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

regular expression question?

Status
Not open for further replies.

markshen2004

Programmer
Jun 9, 2004
89
CA
Hi there

I need write a regular expression for ASP programming.I have to search according to the conditions.

- 8 characters maximum
- Position 1 (if it exist) -- numeric only
- Position 2 (if it exist) -- alpha-numeric -- "1 - 0; A - R;"
- Position 3 (if it exist) -- alpha-numeric -- "1 - 0; A - Z;"
- Position 4 - 8 (if they exist) -- numeric only

I write it as /[0-9][1-0A-R][1-0A-Z][0-9]{1,5}/. but I do not know why it doesn't work.

Please give me some idea to modify it.

Thanks a lot


 
That is a lot of flixibility in the string.

I think this will help:
/^[0-9]?[1-0A-R]?[1-0A-Z]?[0-9]{1,5}$/

^ = start of input
$ = end of input
? = 0 or 1 times
 
one small change:
/^[0-9]?[1-0A-R]?[1-0A-Z]?([0-9]{1,5})?$/

nevermoor: the numbers also may not exist...


Known is handfull, Unknown is worldfull
 
I'm a little confused, how can you have a requirement that may not exist?
I mean if character one doesn't exist, doesn't that mean that there can't be a character 2, 3, 4, etc? Otherwise they would be called character 1, 2, 3, etc.
I can kind of see how your string could be 0 to 8 characters as long as they each follow their own rules based on their position, or is it possible to us a blank to skip a character? (or something like that)

Even so, the above expressions will accept things like:
AA5 because it can say 0 of the first group, 1 of the 2nd, 1 of the 3rd, 1 of the 4th.

Also, I don't believe 1-0 is a vlid range of characters, it would need to be 0-1 or even just 01.

If you mean for the pattern to hold from 0 to 8 characers, but always in that format, you may need to look at something like:
^([0-9]([01A-R]([01A-Z]([0-9]{0,5})?)?)?)?$

Now the lineup should be more correct. If there is a blank string everything is good.
If there is one character it has to be [0-9], two characters it would have to be [0-9][01A-R], etc

At least I think thats it, someone correct me if I missed something. The concept should be correct though. You need a way to cancel out all later groups in th event that an earlier group has a character it should match against. The previous solutions allowed you to skip groups that didn't match, which would allow incorrect strings of less then 8 characters.

-T

[sub]01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111[/sub]
Need an expensive ASP developer in the North Carolina area? Feel free to let me know.


 
>>I'm a little confused, how can you have a requirement that may not exist?

thats something i thought, but who konws??? :)

Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top