How can I create regex rule for name in Track1, following these rules:
I tried:
\^[^\^!"&'*+,:;<=>@_\[\]\\#%?]{2,26}\^ Result FAIL: removing "/" will pass pattern
\^([-.()0-9a-zA-Z]*\/[-.()\w\s\/]*){1,26}\^ Result FAIL: more than 26 characters will pass pattern
^[-.()\w\s\/]{2,26}\^ Result FAIL: removing "/" will pass pattern
Sample of Name in Track1:
TEST/TEST
^- Should PassTEST TEST
^- Should FailTEST/TE/ST
^ - Should FailTEST/TE+ST
^ - Should FailThanks!
If there has to be at least ^
at the start and end, and there has to be at least a single /
then the minimum amount of characters would be 3 instead of 2.
In that case, you might use:
\^(?=[A-Z .()\/-]{1,24}\^)[A-Z .()-]*\/[A-Z .()-]*\^
Explanation
\^
Match ^
(?=[A-Z .()\/-]{1,24}\^)
Positive lookahead, assert 1,24 of the allowed chars followed by ^
to the right to make a total of 2-26 characters[A-Z .()-]*\/[A-Z .()-]*
Match /
between optional allowed chars\^
Match ^
See a regex demo.
If the /
can not be at the start or at the end (matching at least 5 characters in that case)
\^(?=[A-Z .()\/-]{1,24}\^)[A-Z .()-]+\/[A-Z .()-]+\^
See another regex demo