Got more questions? Find advice on: ASP | SQL | XML | Windows
in Search
Welcome to RegexAdvice Sign in | Join | Help

Excluding a range of numbers

Last post 07-26-2008, 6:26 AM by kurowskydb. 2 replies.
Sort Posts: Previous Next
  •  07-24-2008, 4:10 PM 44537

    Excluding a range of numbers

    Trying to exclude a certain range of numbers (interface numbers to be exact) from being matched.

    data set:

    interface1

    interface2

    ...

    interface 700

    interface 701

    Need to exclude  interfaces 300 - 399  while matching 31, 32 etc.

     Any help is GREATLY apprectiated!

     

    -b

  •  07-24-2008, 7:17 PM 44545 in reply to 44537

    Re: Excluding a range of numbers

    Without knowing the regex/language being used I just hope that your supports the lookahead function:

    ^interface\s*(?!3\d\d)

    I'm assuming that the text 'interface' starts at the beginning of the line - if not then remove the '^' at the start. Also, you example shows the early numbers don;t have a space between the 'interface' text and the following digit(s), while the last examples do. My suggestion allows for this with the '\s*' which can be modified as necessary.

    If you want the number included as well, then add "\d{3}"  or "\d+" on the end.

    My test cases were:

    interface1
    interface2
    interface29
    interface30
    interface31
    interface39
    interface40
    interface299
    interface300
    interface301
    interface310
    interface398
    interface399
    interface400
    interface 700
    interface 701

    and the above correctly identified all except those with number form 300 to 399. However it will fail to identify "interface3063" as it only looks ahead 3 digits and doesn't care about what happens after that, but you have not specified the correct behaviour in this case.

    Susan 

  •  07-26-2008, 6:26 AM 44591 in reply to 44545

    Re: Excluding a range of numbers

    Thank you Susan that got it.  I was so close... :).

    Just couldn't get the syntax right.

    Btw it's perl and those spaces at the end were just a typo.

     

    Thanks again.

     -Brian

     

    Filed under:
View as RSS news feed in XML