SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Evangelist
    Join Date
    Jun 2008
    Posts
    455
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    regular expression exceptions

    Hi,

    I have regular expression searching for all strings that are structure like this: {string}.

    What I would like is to be able to make 'exceptions'. For example, I want it to essentially ignore string that have certain words within them, like {form-string}, {ignore-string}, etc.

    This is my current expression,
    PHP Code:
    /(\{[a-z\-]+\})/ 
    How can it be modified to suit my needs?

    Thanks,
    Michael.

  2. #2
    @php.net Salathe's Avatar
    Join Date
    Dec 2004
    Location
    Edinburgh
    Posts
    1,397
    Mentioned
    63 Post(s)
    Tagged
    0 Thread(s)
    You could use a lookahead to see if the token is one of the exceptions, though this will quickly get out of hand with lots of exceptions.
    Code:
    /{(?!(?:form-string|ignore-string)})[a-z-]+}/
    Depending on what precisely you are doing, it may be simpler, faster and/or easier to use some other method (which is difficult to guess without more info.).
    Salathe
    Software Developer and PHP Manual Author.

  3. #3
    SitePoint Evangelist
    Join Date
    Jun 2008
    Posts
    455
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, but i've changed my approach to the problem.

    Thanks for your help.


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
  •