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

    Join Date
    Oct 2010
    Posts
    8
    Rep Power
    0

    Help with negative lookahead in regular expression.


    I am creating a tool which has a command line option "-d" to specify which usb device to use. I need to make sure there are no characters and I was tyring to use a negative-lookahead. Why doesn't this work in my .l file? :

    Code:
    -device { 
        BEGIN DEVICE_NUM; 
    }
    <DEVICE_NUM>[ ]+   /* ignore whitespace */
    <DEVICE_NUM>^(?!.[a-zA-Z]*)[0-9]+$  {  // fails here
    .............
    I get this error:
    "./mytool.l", line 262: unrecognized rule


    please help
  2. #2
  3. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,294
    Rep Power
    9400
    You don't have to check for letters if you require only digits.
    Code:
    <DEVICE_NUM>^[0-9 ]+$
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2010
    Posts
    8
    Rep Power
    0
    Originally Posted by requinix
    You don't have to check for letters if you require only digits.
    Code:
    <DEVICE_NUM>^[0-9 ]+$
    I did that but if someone enters an invalid parameter like FTQ7VVR

    it will extract the 7 - that's why I need to make sure only a digit 0-9 is entered. please help

IMN logo majestic logo threadwatch logo seochat tools logo