选择正则表达式中的部分行

问题描述 投票:0回答:1

I have this string

#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# ...所以为了我写这个表达式:^(^\#.\#)但它只是选择第一行。我怎么能选择第一个#.##.#的最后?

regex regular-language
1个回答
3
投票

您可以使用

^(#\d+#)(.+)\1$

这将捕获组中的第一个#s,重复任何字符,然后匹配第一组中匹配的相同字符。您想要的字符串将位于第二个捕获的组中。

https://regex101.com/r/7Er0Ch/5

© www.soinside.com 2019 - 2024. All rights reserved.