我正在使用Notepad ++并需要一个正则表达式来删除目标之前的所有字符(如果存在)。有些线路根本没有目标,在这种情况下我想保持线路不变。
In this example lets use a "<" character:
This line doesn't have one
This line does <keep>
This line also <and we'll keep all this
This line doesn't either
This line <has two< in it
Results:
This line doesn't have one
<keep>
<and we'll keep all this
This line doesn't either
<has two< in it
提前致谢
答案 0 :(得分:0)
^.*?(<.*)
$1
<强>解释强>
^ : beginig of line
.*? : 0 or more any character, not greedy
(<.*) : group 1, '<' followed by 0 or more any character
$ : end of line
. matches newline
给定示例的结果:
This line doesn't have one
<keep>
<and we'll keep all this
This line doesn't either
<has two< in it
答案 1 :(得分:0)
您可以使用/^.*?(?=<)/m
代替。