SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Wizard spence_noodle's Avatar
    Join Date
    Jan 2004
    Location
    uk, Leeds (area)
    Posts
    1,264
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)

    Is this regex correct?

    Hi folks,

    I'm trying to get 'preg_match' to find/match 'e.g. - London, UK'. I have '/e\.g\.\s\-\sLondon,\sUK/', is this the correct format?

    I have even tried 'e\.g\.' in the the hope it will just find 'e.g.' but with no results.

    spence
    "Don't you just love it when you solve a programming bug only to create another."

  2. #2
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    That's VERY specific, and technically, you're not looking for a pattern. So personally, I'd just go with strpos and the like to test for its existence.
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  3. #3
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Got to agree with Anthony on this.

    However, if (and only if) this IS part of an actual pattern match, I don't think you'd need to escape the dash.
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  4. #4
    SitePoint Wizard spence_noodle's Avatar
    Join Date
    Jan 2004
    Location
    uk, Leeds (area)
    Posts
    1,264
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    Yea it is I must admit, but it is from a location field where the user could place 'Essex'. What I'm thinking now is using preg_match but change the 'e.g.' to just 'eg', then hopfully that will do, if not then the word 'example' will be used instead.
    "Don't you just love it when you solve a programming bug only to create another."


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
  •