Regular expression question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • PSD
    PornSiteDomains.com
    • Oct 2002
    • 1265

    #1

    Regular expression question

    Using php I would like to detect something in a string depending on whether the part immediately after the matched part does not contain certain characters. I think I may need to use a lookahead negative assertion as explained here but it is not working as I would expect so not sure. So for example:

    Code:
    $string = 'test aadfadf random text kalkdfjakdf>apple peach orange';
    I want an expression that will detect everything up to the > so long as apple does not immediately follow the >

    I tried

    Code:
    if(preg_match("/test(.*)>(?!apple))/i",$string)){
    echo 'true since apple does not follow > in string';
    }else{
    echo 'false since apple follows > in string';
    }
    When the string contains apple after the > it returns false as I expect and need but when I change the string to have peach after the > instead of apple it still returns false and I need it to return true. Any ideas?
    PornSiteDomains.com
  • freecartoonporn
    Confirmed User
    • Jan 2012
    • 7683

    #2
    try stackoverflow, i do the same and get issues solved within minutes...

    first thing make sure you have regex part correct ...
    and then the php is the very easy.
    SSD Cloud Server, VPS Server, Simple Cloud Hosting | DigitalOcean

    Comment

    • PSD
      PornSiteDomains.com
      • Oct 2002
      • 1265

      #3
      ha, I did endup there and your right got answer right away, had an extra parenthese at the end. Thanks for the reply.
      PornSiteDomains.com

      Comment

      • freecartoonporn
        Confirmed User
        • Jan 2012
        • 7683

        #4
        Originally posted by JCK
        ha, I did endup there and your right got answer right away, had an extra parenthese at the end. Thanks for the reply.
        np, just hit the thanks button.
        SSD Cloud Server, VPS Server, Simple Cloud Hosting | DigitalOcean

        Comment

        Working...