Question

I need to write a regular expression to match an unknown number of 6 digit "strings" separated by a forward slash

123456 - pass

123456/123457 - pass

123456/123r43 - fail

123456/12 - fail

And it could be a series of more than 2 sets of item numbers...

I've got the following regex that appears to work, in PHP or another lanaguage, however, infopath does not seem to like $ as an end-of-string matcher.

([0-9]{6}\/?)+$

If I remove the $ the example 123456/12 will pass, when it should fail. Is there a different way to write that regex that will solve this problem, or will I have to go in and write some validation code underneath the form? (which I am not opposed to doing)

Thanks!

Était-ce utile?

La solution

You can use a negative look-ahead to mimic $:

[0-9]{6}(\/[0-9]{6})*(?!.)

Using [0-9] instead of \d because the latter could have unicode digit chars.

If needed, you can use a negative look-behind to mimic ^ as well:

(?<!.)[0-9]{6}(\/[0-9]{6})*(?!.)
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top