0

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!

1 Answer 1

1

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})*(?!.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.