[英]Regex to find lines that match a specific pattern
I have a txt file and it has the data has a ///////////
to divide the results.我有一个 txt 文件,它的数据有一个///////////
来划分结果。 I need to find the results that only have 1 line.我需要找到只有 1 行的结果。
I've tried but I can't seem to figure out how to differentiate the multiple lines between the ///////////
我已经尝试过,但我似乎无法弄清楚如何区分///////////
之间的多行
For example, I just need to find the a and the d.例如,我只需要找到 a 和 d。
///////////
a
///////////
b
c
//////////
d
/////////
This will pull the letters you need into a capturing group:这会将您需要的字母拉入捕获组:
\/+\s+(\S+)\s+(?=\/+)
Explanation:解释:
/
, followed by至少一个/
,后跟\s
(includes newlines), followed by至少一个空格\s
(包括换行符),后跟\S
, followed by至少一个非空白字符\S
,后跟\s
, and至少一个空格\s
和/
, in a positive lookahead group至少一个/
,在一个积极的前瞻组中Demo: https://regex101.com/r/pHg9ov/3演示: https://regex101.com/r/pHg9ov/3
^/+\R\K.+(?=\R/+$)
查找内容: ^/+\R\K.+(?=\R/+$)
. matches newline
取消选中. matches newline
. matches newline
Explanation:解释:
^ # beginning of line
/+ # 1 or more slashes
\R # any kind of linebreak
\K # reset match
.+ # 1 or more any character but newline
(?= # positive look ahead, make sure we have after:
\R # any kind of linebreak
/+ # 1 or more slashes
$ # end of ine
) # end look ahead
Screenshot (before):截图(之前):
Screenshot (after):截图(之后):
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.