简体   繁体   English

正则表达式:不以短语开头的匹配行

[英]Regex: Match lines NOT starting with phrase

I found this question about negative lookaheads, but it doesn't work for me in Regexr (which I use to validate regular expressions): Find lines not starting with " in Notepad++ 我发现了有关否定前瞻的问题,但在Regexr(我用来验证正则表达式)中对我不起作用: 在Notepad ++中查找不以“开头”的行

http://www.regexr.com/ http://www.regexr.com/

I want to match every line that does not start with "Sold, ship now" 我想匹配所有不以“已售出,立即发货”开头的行

Currently, on regexr, when I use the expression ^(?!Sold, ship now) on the following text: 当前,在regexr上,当我在以下文本上使用表达式^(?!Sold, ship now)时:

Sold, ship now: [FreeEconomy Shipping]

Sold, NOT ship now: [FreeEconomy Shipping]

Sold, ship now: [FreeEconomy Shipping]

I receive 0 matches. 我收到0场比赛。

You'll need to use the multiline flag. 您需要使用多行标志。 Which, in the case of regexr , can be activated like so: 对于regexr ,可以这样激活:

regexr多行标志

Also, if you'd like to return the entirity of the lines that do not begin with Sold, ship now , I'd recommend utilizing dot plus in your expression: 另外,如果您想返回不是以Sold, ship now开头的行的完整性,请立即Sold, ship now ,我建议在表达式中使用点加号:

^(?!Sold, ship now).+

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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