regex - Negative look-ahead expression -


i'm writing perl script performs different actions on hosts depending on patterns match fqdn. i've been struggling find regular expression skips hosts have string 'test' in domain name.

these host names represent 4 host name types i'm dealing with:

  • node01.prod.com
  • node01.test.com
  • node02.dmz.prod.com
  • node02.dmz.test.com

the following expression matches host name pattern i'm trying skip:

/\w\.test/ 

but, none of negative look-ahead expressions i've tried skip host names 'test'. example, expression:

/\w\.(?!test)/ 

matches/passes 4 host name types, including 2 contain string 'test'.

what's driving me crazy if hard code part of host name, negative look-ahead expression skip full host name:

/node01\.(?!test)/    # matches node01.prod.com 

i'm surely missing terribly obvious - suggestions?

the problem you're putting negative lookahead after match, allows match partial node name if has word test in somewhere.

this expression match string doesn't contain test:

(?!.*test)^.*$ 

online demonstration:

http://regex101.com/r/rz0vo2


Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -