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

    Join Date
    Dec 2012
    Posts
    2
    Rep Power
    0

    Simple regex help


    I'm a newbie at regex and need some help with the following. I want to match ABC and anything with number + ABC so ABC, 1ABC, 2ABC, etc. would be valid but not match anything else such as ABCD, KABC, 2ABCD. ABC could be variable in length. This is what I've tried the re below but I don't think that's correct. Can someone pls help out?

    Code:
    \dABC|^ABC
  2. #2
  3. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,068
    Rep Power
    9398
    Try more like
    1. The string starts with zero or more numbers
    2. Followed by the letters "ABC"
    3. Followed by the end of the string
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    2
    Rep Power
    0
    yes that is exactly what i want - i just wanted to elaborate on the edge cases that were eluding my RE. any advice for the actual RE?
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2012
    Posts
    832
    Rep Power
    496
    You are saying that your RE should not match "2ABCD", but, at the same time that ABC could be variable in length. That sounds as a contradiction to me, so I am afraid you are not being sufficiently precise about what your RE should match and what it should not match.

    Comments on this post

    • requinix agrees : good catch

IMN logo majestic logo threadwatch logo seochat tools logo