Re: [PHP] Deleting multiple backslashes; regex?

[email protected] (Al)
Newsgroups php.general,php.general
Message-ID <[email protected]>

On 3/15/2010 3:30 PM, Ashley Sheridan wrote:
> On Mon, 2010-03-15 at 15:35 -0400, Al Rider wrote:
>
>>
>>
>> On 3/15/2010 3:11 PM, Ashley Sheridan wrote:
>>
>>> On Mon, 2010-03-15 at 15:03 -0400, Al wrote:
>>>
>>>> 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.
>>>
>>
>>
>> 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.
>>
>>> Thanks,
>>> Ash
>>> http://www.ashleysheridan.co.uk
>>>
>>>
>>>
>
>
> 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.uk
>
>
>

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.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.