use*_*848 2 regex notepad++ regex-lookarounds
我正在使用notepad++并希望找到特定字符串出现的上下文.
所以搜索字符串是0wh.*0subj,我想在它之前和之后找到这个搜索项加上4行.
eg: xxx means whatever is on a new line. the search result should be:
xxx
xxx
xxx
xxx
0wh.*0subj
xxx
xxx
xxx
xxx
Run Code Online (Sandbox Code Playgroud)
我试过using \n\r但它不起作用.我们将非常感谢所提供的任何帮助.
问候
这将适用于Notepad ++(已测试):
(?m)(^[^\r\n]*\R+){4}0wh\.\*0subj[^\r\n]*\R+(^[^\r\n]*\R+){4}
Run Code Online (Sandbox Code Playgroud)
在屏幕截图中,请注意未选择555行.这只是当前的路线.

解释正则表达式
(?m) # set flags for this block (with ^ and $
# matching start and end of line) (case-
# sensitive) (with . not matching \n)
# (matching whitespace and # normally)
( # group and capture to \1 (4 times):
^ # the beginning of a "line"
[^\r\n]* # any character except: '\r' (carriage
# return), '\n' (newline) (0 or more times
# (matching the most amount possible))
\R+ # 'R' (1 or more times (matching the most
# amount possible))
){4} # end of \1 (NOTE: because you are using a
# quantifier on this capture, only the LAST
# repetition of the captured pattern will be
# stored in \1)
0wh # '0wh'
\. # '.'
\* # '*'
0subj # '0subj'
[^\r\n]* # any character except: '\r' (carriage
# return), '\n' (newline) (0 or more times
# (matching the most amount possible))
\R+ # 'R' (1 or more times (matching the most
# amount possible))
( # group and capture to \2 (4 times):
^ # the beginning of a "line"
[^\r\n]* # any character except: '\r' (carriage
# return), '\n' (newline) (0 or more times
# (matching the most amount possible))
\R+ # 'R' (1 or more times (matching the most
# amount possible))
){4} # end of \2 (NOTE: because you are using a
# quantifier on this capture, only the LAST
# repetition of the captured pattern will be
# stored in \2)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3777 次 |
| 最近记录: |