PHP Regexp replace all question marks before a slash

Hey guys,

I’ve been struggling with this tricky REGEXP replace…

Basically, I want to replace all question marks with an @ symbol that appear BEFORE a slash. Only the ones that appear before the slash, leaving the ones that appear after the slash untouched.

For example:
Before

hey?how?are?you/i?am?fine

After

hey@how@are@you/i?am?fine

I’d reallllyyy appreciate some help.

Nevermind guys. I figured it out finally, sorry!

$string = preg_replace(/\\?(?=.*\\/)/i,'@',$string)

Basically, this says replace all question marks that have any character after them and finally a / … So the first set of question marks match this because they have characters after them and then the slash, but the second set does not match because there is no slash afterwards