JS Regex Expresssion

Discussion in 'JavaScript' started by Borduhh, Sep 18, 2017.

  1. #1
    Hi all,

    I am looking for a regex expression that will match the following:

    http://example.com/FindMe/john
    http://example.com/FindMe/Jill
    http://example.com/FindMe/boo/who?=d
    http://example.com/FindMe/adamdasfaam
    http://example.com/FindMe/ddafdf/adfkhjhad/adsfjd/jddhadk

    because they all contain the term "FindMe".

    However, it wouldn't match the following because they do not contain that term:

    http://example.com/about-us
    http://example.com/contact
    http://example.com/shop
    http://example.com/help-me-please

    Any help would be greatly appreciated.
     
    Borduhh, Sep 18, 2017 IP
  2. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #2
    PoPSiCLe, Sep 20, 2017 IP
  3. Roger Luis

    Roger Luis Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #3
    var str = "http://example.com/FindMe/john"
    var patt = new RegExp("\/FindMe\/")
    var res = patt.test(str)
    // now variable res is true if str contain /FindMe/
    Code (JavaScript):
     
    Roger Luis, Nov 1, 2017 IP