在正则表达式中选择部分行 [英] Select part of line in regular expression
本文介绍了在正则表达式中选择部分行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
#1#http://test.ir:8080/srvSC.svc#1#
#2#http://test.ir:8081/srvSC.svc#2#
#3#http://test.ir:8082/srvSC.svc#3#
#4#http://test.ir:8083/srvSC.svc#4#
#5#http://test.ir:8084/srvSC.svc#5#
#6#http://test.ir:8085/srvSC.svc#6#
我想选择所有 #1# #2# ...
所以为了我写这个表达式:^(^\#.\#)
但是它只是选择第一行.我怎么能选择第一个 #.#
和最后一个 #.#
?
I want to select all #1# #2# ...
so in order to i wrote this expression : ^(^\#.\#)
but it just select first line.How could i select first #.#
and last of #.#
?
推荐答案
可以使用
^(#\d+#)(.+)\1$
这将捕获组中的第一个 #
,重复任何字符,然后匹配在第一组中匹配的相同字符.您想要的字符串将在第二个捕获组中.
That will capture the first #
s in a group, repeat any characters, and then match the same characters that were matched in the first group. The string you want will be in the second captured group.
https://regex101.com/r/7Er0Ch/5
这篇关于在正则表达式中选择部分行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文