Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them, it only takes a minute:

I'm not great with regex and I am trying to search a string for "&option=" plus a number [0-100].

So far i have this :

$link = str_replace("^&option[0-9]"," ",$actual_link);

Can any one help me with the correct regex expression?

share|improve this question
2  
It would be preg_replace as opposed to str_replace – Ohgodwhy Mar 29 '14 at 21:57
    
perfect thank you haha such a simple fix +1 if you could on a comment – andrew hutchings Mar 29 '14 at 21:59

1 Answer 1

up vote 3 down vote accepted

Whatever its $ or & (confused by your question), use preg_replace() for your regex replace.

$link = preg_replace("/[&$]option=(?:100|[0-9]|[1-9][0-9])\b/"," ",$actual_link);

And I don't think you need that ^ for the anchoring!

share|improve this answer
    
edited my question too many variables have been written this day. thank you – andrew hutchings Mar 29 '14 at 22:00
    
@andrewhutchings it doesn't matter. It handles both. If you need to remove $, just erase from there! – Sabuj Hassan Mar 29 '14 at 22:02

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.