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 .).

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.