Re: Deleting multiple backslashes; regex?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Double check your code I came up with the same solution as Ash did and it
worked fine in Wamp.

On Mon, Mar 15, 2010 at 3:30 PM, Ashley Sheridan
<ash@xxxxxxxxxxxxxxxxxxxx>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
>
>
>

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux