tags:

views:

78

answers:

5

hi everyone. 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 lower case.

+8  A: 
^[a-z]+_[a-z]+$
Marco
+2  A: 

You just need:

[a-z]+_[a-z]+

or if it needs to be an entire line:

^[a-z]+_[a-z]+$

Paul R
+4  A: 

Try this:

[A-Za-z]+_[A-Za-z]+

Lowercase :

 [a-z]+_[a-z]+
c0mrade
+6  A: 

Try:

^[a-z]+_[a-z]+$
Ardman
+1  A: 

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)

Remo.D