Matching strings with letters and a semicolon

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

Matching strings with letters and a semicolon

Post by tecktalkcm0391 »

How can I use preg_match to match only letters, a semicolon, and spaces?
GuitarheadCA
Forum Newbie
Posts: 20
Joined: Fri Jul 13, 2007 12:59 am

Post by GuitarheadCA »

Not real sure here, but I'd give this one a shot:

[a-zA-Z\;\ ]+

Let me know if that works.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Close..

Code: Select all

preg_match('#^[a-z;\s]*$#i', $string);
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

Post 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!
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

That is a colon, not a semicolon. Change it in the code I posted above.
Post Reply