开发者

Regex check previous line

开发者 https://www.devze.com 2022-12-11 03:40 出处:网络
Using regex (in c#.net) is it possible to check the previous line of a string? For instance, I need to select strings in which the previo开发者_运维技巧us line is not a series of asterisks (prev line

Using regex (in c#.net) is it possible to check the previous line of a string?

For instance, I need to select strings in which the previo开发者_运维技巧us line is not a series of asterisks (prev line:******)


(?m)^(?<!^\*+\r?\n).+

(?m) turns on multiline mode so ^ can match the beginning of a line. The lookbehind checks the previous line; if it succeeds (that is, it doesn't see a line of asterisks), .+ consumes the current line.


You can use RegexOptions.MultiLine and then match something like the following:

(?<!^\*+$\r?\n?.*)foo

This matches "foo" only if the previous line doesn't consist of asterisks.

0

精彩评论

暂无评论...
验证码 换一张
取 消