简体   繁体   中英

Match everything but Regular Expression

Been searching for a long time, reading up about negative/positive outlook but can't get this to match everything but my regular expression.

\\b[AZ]{1}\\d{3,6}[A-Z0-9]+

is the string I don't want to extract.

(?!\\b[AZ]{1}\\d{3,6}[A-Z0-9]+).*

is my best attempt using Negative Outlook , but it will still match the data.


I am using this Regex on:

11/02/2019 1 475.50 453.345 Serial number : C580A0453WD7996 AFJ_LowGuard_NewNew End User Details:


The output I want is:

11/02/2019 1 475.50 453.345 Serial number : AFJ_LowGuard_NewNew End User Details:

You can either use your regex to match and replace the match with empty string, that's one approach.

Another approach that you seem to be trying is, you can use this following regex to match anything but your regex,

\b(?:(?![A-Z]\d{3,6}[A-Z0-9]+).)+\b

Demo

This will match anything except your pattern. But personally I suggest replacing by matching your pattern should be easy.

Edit:

Ok I read your comment that you want to replace anything except the string matched by your pattern. In that case you can use following regex to match everything except your pattern and replace it with empty string to get your result,

\b(?:(?![A-Z]\d{3,6}[A-Z0-9]+).)+

Demo with replacement with empty string

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM