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

    Join Date
    Aug 2017
    Posts
    2
    Rep Power
    0

    Regex to include lines not containing text


    I am trying to write a regular expression where I am trying to retrieve all the lines that do not contain the text DEBUG.
    In the below example

    Code:
    TEST_DEBUG ref number: 1234
    TEST ref number: 1234
    QA_DEBUG ref number: 4556
    QA ref number: 3455
    I only need to get
    Code:
    TEST ref number: 1234
    QA ref number: 3455
    Here is the expression I tried

    ([A-Z]\w+)(?!_DEBUG).*?(.*?(\d+)

    This is returning me all rows instead of the ones without DEBUG text.
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2017
    Posts
    2
    Rep Power
    0
    This is my regex -
    Code:
    ([A-Z]\w+)(?!_DEBUG).*?(:).*?(\d+)
  4. #3
  5. Lazy Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,394
    Rep Power
    9645
    The [A-Z]\w+ will match "TEST_DEBUG" and "QA_DEBUG" so the (?!) will not match.

    Put the (?!) at the beginning of the line and anchor it in place with a ^.
    Code:
    ^(?![A-Z]+_DEBUG)([A-Z]\w+).*?(:).*?(\d+)

IMN logo majestic logo threadwatch logo seochat tools logo