RegEx Help

  • Thread starter Thread starter Franklin
  • Start date Start date
F

Franklin

I need to come up with a regex that tests for conformance to the following
example:

UA-123456-7

To match, the string :
- must start with "UA-" (upper case only)
- followed by exactly six unsigned integers (each can be zero through nine)
- followed by exactly one dash ("-")
- followed by exactly one integer (which can be zero through nine)

Thanks.
 
I need to come up with a regex that tests for conformance to the following
example:

UA-123456-7

To match, the string :
- must start with "UA-" (upper case only)
- followed by exactly six unsigned integers (each can be zero through nine)
- followed by exactly one dash ("-")
- followed by exactly one integer (which can be zero through nine)


Try
^UA-[0-9][0-9][0-9][0-9][0-9][0-9]-[0-9]$

This will work with any regular expression dialect.

/H
 
Franklin said:
I need to come up with a regex that tests for conformance to the following
example:

UA-123456-7

To match, the string :
- must start with "UA-" (upper case only)
- followed by exactly six unsigned integers (each can be zero through nine)
- followed by exactly one dash ("-")
- followed by exactly one integer (which can be zero through nine)

Thanks.

That was a much more precise specification that you usually see. :)

^UA-\d{6}-\d$
 
Back
Top