[Solved] Regular Expression for Employee ID with some restrictions [closed]


mlorbetske’s regex can be rewritten a bit to remove the use of conditional regex. I also remove the redundant 0-9 from the regex, since it has been covered by \d.

^[a-zA-Z\d](?:[a-zA-Z\d]|(?<![._/\\\-])[._/\\\-]){0,49}$

The portion (?:[a-zA-Z\d]|(?<![._/\\\-])[._/\\\-]) matches alphanumeric character, OR special character ., _, /, \, - if the character preceding it is not a special character already. I also make the group non-capturing (?:pattern), since it seems that the regex is used for validation only.

I made use of the zero-width negative look-behind assertion (?<!pattern) to assert the character in front is not one of the special characters.

solved Regular Expression for Employee ID with some restrictions [closed]