a开发者_JS百科bcVIRTUAL123 ^(?!.*VIRTUAL).*$^([a-zA-Z]{3})([a-zA-z0-9]{7})(\d{3})$ FALSE
abcVIRTUAL123 ^([a-zA-Z]{3})([a-zA-z0-9]{7})(\d{3})$ TRUE
abcLOCATOR123 ^(?!.*VIRTUAL).*$^([a-zA-Z]{3})([a-zA-z0-9]{7})(\d{3})$ FALSE
abcLOCATOR123 ^([a-zA-Z]{3})([a-zA-z0-9]{7})(\d{3})$ TRUE
Hi there, I'm new to REGEX and am using the VBScript library from with Excel.
In the above example I want to check if the string contains the word 'VIRTUAL' and if so return a false match. I think its nearly there all except that the remainder of the pattern makes the string valid. Its ignoring my first negative look ahead.
I've tried various combinations from the forums but am stuck.
Any help appreciated.
Cheers Nik
This one: ^([a-zA-Z]{3})(?!VIRTUAL)[a-zA-Z]{7}\d{3}$
Maybe better match this pattern ^([a-zA-Z]{3})VIRTUAL\d{3}$
and invert result?
You've got $^
in the middle of your regex which means "end of string, followed by start of string". Of course this can never match.
Try
^(?!.*VIRTUAL)([a-zA-Z]{3})([a-zA-z0-9]{7})(\d{3})$
精彩评论