#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2000
    Location
    Montreal, Canada
    Posts
    72
    Rep Power
    14

    Question Helo with REGEX ......Substitute for SQL Like


    Hello peeps ........REGEX is officially that part of programming my brain is just not going to have to master. Got a simple problem.

    Supposing that I have a word "pine"

    I then want to do a REGEX check against a word so that if it starts with "pine" return true.

    eg. check("pineapple") will return true

    check ("pinacolada") will return false.

    check ("monthend") will return false.

    check("pinebottle") will return true.

    Something like how in SQL you do a LIKE 'PINE%'
    Visit my PHP V-Portal.
    http://www.naijaryders.com
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2009
    Posts
    309
    Rep Power
    162
    Try ^pine
    This will only match if it's the *first* word of the string you're matching it on though. If it's in the middle of a string somewhere, you could just use the word pine, but that would mean it also matches words like randompinerandom which is not what you're looking for.

    *edit* I just thought of something else as well, which would make it match anywhere in the string, as long as the word starts with pine. This won't match if it is the first word in the string though because it matches a space before the word: \spine

IMN logo majestic logo threadwatch logo seochat tools logo