0

What I want to do is remove all instances of c_*/ where * could be any digit or character of any length.

$cano = 'www.example.com/example/example2/c_3/example4/';
$cano = preg_replace('c_*/', '', $cano);

I've always been bad with these cause I hardly use them...

1
  • Did my answer help at all? I can alter it if it's not what you're looking for. Commented Oct 31, 2012 at 2:29

2 Answers 2

3

I think this will do the trick.

$cano = preg_replace('#c_[^/]+/#', '', $cano);

The [^/] matches any character that is not a forward slash, and the + means "one or more" characters.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks... worked great... threw it into an array with some others and working as expected.
0

Try this:

$cano = 'www.example.com/example/example2/c_3/example4/';
$cano = preg_replace('#(?:c_.[^/]/)+#', '', $cano);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.