SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict svcghost's Avatar
    Join Date
    Oct 2010
    Posts
    288
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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
    Code:
    hey?how?are?you/i?am?fine
    After
    Code:
    hey@how@are@you/i?am?fine
    I'd reallllyyy appreciate some help.

  2. #2
    SitePoint Addict svcghost's Avatar
    Join Date
    Oct 2010
    Posts
    288
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nevermind guys. I figured it out finally, sorry!

    Code:
    $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


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •