in reply to A single regex
It's either going to have a letter before an (optional) underscore, or it's going to have an underscore before a letter. Surrounding and intervening characters can be letters or numbers./^[a-z0-9]*(?:[a-z][a-z0-9]*_?|_[a-z0-9]*[a-z])[a-z0-9]*$/i
A lookahead solution would check that there's no more than one optional underscore, and that there's at least one letter:
In both cases, you're kind of doing multiple regexes./^(?=[^_]*_?[^_]*$)\w*[a-z]\w*$/i;
|
|---|