Regex to validate for Unique Well Identifier in rails

Posted by Jasper502 on Stack Overflow See other posts from Stack Overflow or by Jasper502
Published on 2012-03-29T05:11:30Z Indexed on 2012/03/29 5:29 UTC
Read the original article Hit count: 208

Filed under:
|

I am a regex newbie and can't seem to figure this one out.

Here is a link to the required string formats:

http://earth.gov.bc.ca/royp-bin/phcgi.exe?PH_QKC=DOCUWI&PH_APP=RMSprodApp&PH_HTML=DOCUWI.htm

For example:

100041506421W500 = 1+0+{01-16}+{01-36}+{001-129}+{01-36}+W+{1-6}+0+{0-9}

I tried this:

^10[0|2-9]{1}0*([1-9]|1[0-6])0*([1-9]|[12][0-9]|3[0-6])0*([1-9][0-9]|1[0-2][0-9])0*([1-9]|[12][0-9]|3[0-6])W[1-6]0[0-9]$

In a regex validator and it sort of works except that 1041506421W500 and 10000000041506421W500 validates. The entire string can only be 16 characters long.

I am pretty sure I am missing something obvious here regarding the leading zeros. Tried the NTS format and running into the same sort of problems.

© Stack Overflow or respective owner

Related posts about regex

Related posts about ruby-on-rails-3