Simple regex

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

Moderator: General Moderators

Post Reply
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Simple regex

Post by alex.barylski »

Code: Select all

$temp = preg_replace('/[^a-z]/ig', '', $temp);
Would this strip any characters except A to Z???

Thus:

Code: Select all

$temp = 'The quick/Brown fox/Jumped over - the lazy dog';
would yield:

Code: Select all

$temp = 'ThequickBrownfoxJumpedoverthelazydog';
If it doesn't, how can I accomplish this using regex???

Also...

when I use the above REGEX...I don't suppose this is portable to other languages other than English???

What I mean is...in french...some characters have that little apostrphe, but are still considered valid characters in the range of A-Z aren't they???

Cheers :)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

there is no g modifier for pcre, it's global always in the case of preg_replace() ;)

it will not capture accented characters.
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post by alex.barylski »

feyd wrote:there is no g modifier for pcre, it's global always in the case of preg_replace() ;)

it will not capture accented characters.
Wicked...thanks :)
Post Reply