Regular Expression to find sequences of lowercase letters joined with underscore
I can't seem to make my regular expression work.
I'd like to have some alpha text, no numbers, an underscore and then some more aplha text.
for example: blah_blah
I have an non-working example here
^[a-z][_][a-z]$
Thanks in advance people.
EDIT: I apologize, I'd like to enforce the use of all 开发者_Go百科lower case.
^[a-z]+_[a-z]+$
Try this:
[A-Za-z]+_[A-Za-z]+
Lowercase :
[a-z]+_[a-z]+
You just need:
[a-z]+_[a-z]+
or if it needs to be an entire line:
^[a-z]+_[a-z]+$
Try:
^[a-z]+_[a-z]+$
Depending on which flavor of regex you're using there are a different possibilities:
^[A-Za-z]+_[A-Za-z]+$
^\a+_\a+$
^[[:alpha:]]+_[[:alpha:]]+$
The first form being the most widely accepted.
Your example suggests you're looking for things exactly like "blah_foo" and don't want to extract it from strings like "Hey blah_foo you". If this is not the case, you should drop the "^" (match the beginning of the string) and "$" (match the end of the string)
精彩评论