Since I'm not going to test my regular expressions and since you don't seem to want to provide a SSCCE, let us think about a different approach, rephrasing your problem:
If your string contains an underscore, you want that underscore to be followed by letters and then a number.
If your string contains no underscore, you want to accept it.
When you lok at these two statements, it should be simple for you to encode that as two separate if statements.
If you really want to force this into one regular expression, consider a simple alternation:
/^([^_]+|[^_]+_[a-z]+\d[^_]*)$/
("Either the string contains no underscore, or it contains stuff that is no underscore, followed by an underscore, letters and a digit, and then no underscores again").
Of course, this is all vague since you don't provide code to discuss. |