Reputation: 18612
I need to develop a validation pattern for catching any kind from:
pdf/csv/xlsx
select any separate word is simple:
(pdf|csv|xlsx).
However, I need to check that any combination with them separated by slash is fine as well.
For example, correct flow:
pdf/csv/xlsx
pdf
pdf/csv
csv/xlsx
xlsx
pdf/xlsx
Incorrect:
test
incorrect
doc
Upvotes: 3
Views: 445
Reputation: 18555
This idea makes the pattern a bit shorter:
^(?:(?:pdf|csv|xlsx?)/?\b)+$
The slash is set to optional here and the word boundary \b
requires it between words on the one hand and disallows it at the end on the other. It might be a tiny bit less efficient, but looks cool.
Upvotes: 1
Reputation: 786146
You may use this regex:
^(?:pdf|csv|xlsx?)(?:/(?:pdf|csv|xlsx?))*$
Upvotes: 2