Thread: Test a Match?

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

    Join Date
    Jun 2011
    Posts
    56
    Rep Power
    4

    Test a Match?


    I'm extracting 16 digit numbers from data and would like to verify that I always get a 16 digit number. I've tried something like this:

    Code:
    if ($match =~ /\S{16}/msx){
    
    do something
    }
    
    else{
    
    print "Bad Regex\n";
    exit:
    }
    It's not working. I'm definetly getting the 16 digit numbers in the steps not shown here as I've printed them multiple times. I thought /S{16}/ would match 16 numbers/letters etc... in a row. I need hex so I don't think I can use \d. Any advice?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Apr 2009
    Posts
    1,930
    Rep Power
    1225
    \S matches anything that is not a whitespace character.

    You need to use a character class that only includes 0..9 and a..f or A..F
    Code:
    /\b[0-9a-f]{16}\b/i
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2011
    Posts
    56
    Rep Power
    4
    Originally Posted by FishMonger
    \S matches anything that is not a whitespace character.

    You need to use a character class that only includes 0..9 and a..f or A..F
    Code:
    /\b[0-9a-f]{16}\b/i
    Thanks a lot, but I was breaking my loop to early and not getting to my test at all. I got it now. Thanks again, still learning.
  6. #4
  7. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2012
    Location
    spaceBAR Central
    Posts
    229
    Rep Power
    42
    Originally Posted by dolfantb
    I'm extracting 16 digit numbers from data and would like to verify that I always get a 16 digit number Any advice?
    Post some examples of exactly what you want to match.

IMN logo majestic logo threadwatch logo seochat tools logo