Re: Deleting multiple backslashes; regex?
| From: | Al | Date: | Mon, 15 Mar 2010 20:17:14 +0000 |
| Subject: | Re: Deleting multiple backslashes; regex? | ||
| References: | 1 2 3 4 | Groups: | php.general php.general |
| Request: | Send a blank email to php-general+get-302871@lists.php.net to get a copy of this message | ||
On 3/15/2010 3:30 PM, Ashley Sheridan wrote:
On Mon, 2010-03-15 at 15:35 -0400, Al Rider wrote:Thanks ever so much guys. Sometimes it's helpful when someone else confirms something must work. Problem was that I had a series of cleanup and security checks on a POST array and inadvertently used the original POST array in one of the steps following the backslash remove step, so obviously it didn't work.On 3/15/2010 3:11 PM, Ashley Sheridan wrote:I tried the code I just gave you and it's working, so I'm not sure now what issue you're having with it? Thanks, Ash http://www.ashleysheridan.co.ukOn Mon, 2010-03-15 at 15:03 -0400, Al wrote:I agree, it should work; but, it doesn't. Most everything that looks reasonable works in The Regex Coach, including you suggestion. I'm starting to think there is a bug in the regex engine; haven't looked yet. It's doubtful though because the bug would screw existing code.Anyone have a regex pattern for deleting multiple backslashes e.g., \\\\\\\ I pretty good with regex; but, be damned if I can delete them with preg_replace() I've tried "\\\\" as the manual says preg_replace("/\\\\/", '', $str); preg_replace("/(\\\\)+/", '', $str); preg_replace("/\x5C/", '', $str); preg_replace("/\\x5c/", '', $str); And lots of others. stripslashes() and stripcslashes() are limited.What about this: $str = 'text\\dfnfg\\dhdsg\\\\'; echo preg_replace('/\\\{2,}/', '', $str); I think what was catching you out was that you were escaping the \ once for the regex, but then it needed it again because it was in a single quoted string, meaning 3 slashes in total. Took me a little while to figure that out as well! The {2,} part just tells it to only remove the slashes where they occur in runs of two or more.Thanks, Ash http://www.ashleysheridan.co.uk