views:

320

answers:

4

example strings

785*()&!~`a

##$%$~2343

455frt&*&*

i want to capture the first and the third but not the second since it doesnt contain any alphabet character plz help

+2  A: 

Here is one possible way:

.*[a-zA-Z]+
Guido Domenici
Lieven
@Shabby, if you add .* to the regex, the first and third instances are captured. The regex would then become ".*[a-zA-Z]+.*"
Lieven
+4  A: 

In fact, I think [a-zA-Z] might suffice to match your strings.

To capture the whole thing, try: ^.*[a-zA-Z].*$

Daren Thomas
I agree (my lookahead is not needed). Beware of the "dotall" mode: you do not want '.' to include \r\n
VonC
A: 

This is my favorite RegEx testing site: Javascript Regexp Tester and Cheat Sheet

overslacked
another one is http://www.rubular.com/
chburd
+1  A: 

You should maybe clarify a bit what you mean by 'catpuring': do you want the whole string of just the ascii bits?

Also, you don't say if it should match just plain Roman alphabet (A to Z) or if it should also match Unicode chars to match strings in other languages.

If you just need to test your string, in C# you would do:

bool matching = Regex.IsMatch(myString, "[a-zA-Z]");

You wouldn't need anything else, since just one letter anywhere in the myString string will match (according to your definition).

Renaud Bompuis