Page 1 of 1

Matching strings with letters and a semicolon

Posted: Mon Jul 16, 2007 10:18 pm
by tecktalkcm0391
How can I use preg_match to match only letters, a semicolon, and spaces?

Posted: Mon Jul 16, 2007 10:40 pm
by GuitarheadCA
Not real sure here, but I'd give this one a shot:

[a-zA-Z\;\ ]+

Let me know if that works.

Posted: Mon Jul 16, 2007 10:46 pm
by Benjamin
Close..

Code: Select all

preg_match('#^[a-z;\s]*$#i', $string);

Posted: Mon Jul 16, 2007 10:52 pm
by tecktalkcm0391
Thanks, both didn't work. Maybe its my logic.

I have an array:

Code: Select all

Array ( [0] => 05 [1] => 35 [2] => 03 [3] => 33 [4] => 18 [5] => Extra: 01 )
Note: Extra can be any text with or without spaces.

I want to match only a part of the array that has text in the format of part 5 above.

Thanks!

Posted: Mon Jul 16, 2007 11:04 pm
by Benjamin
That is a colon, not a semicolon. Change it in the code I posted above.