Regex for leading Characters

I have a textbox to accept string.
I want to put a validation in that like, if character X is there in string it should be at last, not in the middle. But X can repeat many times. A string may have 5 X or 10 X, but all X must be at last not in the middle of string.

For e.g.:

testingxxxx This is correct string because all X are at last.

test_x_ingxxxxx This is Invalid because X is in between the string.

testX This is Valid because X at last

XtestXXXX This is Invalid because X at starting position.


Source: regex

Leave a Reply