Search code examples
regexregular-language

Why my string does not match my regular expression pattern?


can somebody tell me why the string below:

ASLTHODSERV001.ABCDE.FGHI.CONTOSO.COM 

does not match the following pattern:

"^\w{6}(?!AADS|ADC|AMOM|ASERV|SMOM|SYSMS)\d{3}.ABCDE.FGHI.CONTOSO.COM" 

Thank you


Solution

  • You need to add extra \w{5} after the negative lookahead so that it would match the 5 word characters which exists before 3 digits.

    ^\w{6}(?!AADS|ADC|AMOM|ASERV|SMOM|SYSMS)\w{5}\d{3}\.ABCDE\.FGHI\.CONTOSO\.COM
    

    or

    ^\w{6}(?!AADS|ADC|AMOM|ASERV|SMOM|SYSMS)[A-Z]*\d{3}\.ABCDE\.FGHI\.CONTOSO\.COM
    

    DEMO