Jump to content

Eliminate trailing and back slashes - escapes ?


scanreg

Recommended Posts

1.) You should consider using preg_replace instead of ereg_replace as the latter is deprecated.

2.) Your pattern matches 1 or more capital V characters anchored to the start of the string and replaces them with noting.

3.) \V would mean any character that is not a vertical whitespace character. So essentially it would match anything that is not a newline character (making it very similar, if not the same as using .).

Oh, my bad. Well if the objective is to match any forward slashes at the start of the string you don't need either backslash as the forward slash character has no special meaning. The only reason to escape it is if you are using PCRE and have used it as a delimiter. But personally I'd suggest using a different delimiter, since the forward slash is all too common in patterns that involve paths or HTML.

but what if I'm trying to match both forward slashes and back slashes:

 

$clean = ereg_replace ("^[\ /]+", "", $not_clean);  (added a space in between for clarity)

 

should it be like this:

 

$clean = ereg_replace ("^[\\ /]+", "", $not_clean);  (added space here too)

 

Thanks :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.