开发者

Regex check previous 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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜