preg_replace and percentage sign

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

Moderator: General Moderators

Post Reply
Pistons
Forum Newbie
Posts: 1
Joined: Tue Mar 09, 2010 2:55 am

preg_replace and percentage sign

Post by Pistons »

I'm using PHP preg_replace to replace all characters except alphabetic and numeric values.
The regex looks like this: /[^a-zA-Z0-9]/u

Now I want to exclude the percentage sign from being replaced also.
So normally the regex would look like this /[^%a-zA-Z0-9]/u , which seems to work with the Dreamweaver regex search tool.
When used with preg_replace, the regex breaks.

I've been searching for hours on how to resolve this, but cannot find a single clue.
User avatar
ridgerunner
Forum Contributor
Posts: 214
Joined: Sun Jul 05, 2009 10:39 pm
Location: SLC, UT

Re: preg_replace and percentage sign

Post by ridgerunner »

Please post the code you are using that breaks. Also provide some "before" and "after" text that the preg_replace is supposed to accomplish.
Post Reply