<span id="blogname"></span>


All that's beautiful drifts away like the waters ——W. B. Yeats
Modisied by Leslie-Cheung.com
 
2025/4/17 15:29:00
正则表达式匹配最后一个指定字符后的内容
 
问题描述
在本示例中,我们将编写一个程序来提取字符串中最后一个指定字符(如“#”)之后的所有内容。例如,对于字符串"abc#123#456",我们想要提取"456"。

正则表达式实现
为了解决这个问题,我们可以使用如下的正则表达式:
.*#(.*)$

这是如何工作的:
.* 表示匹配任意字符零次或多次。
# 是我们指定的字符。
(.*) 是一个捕获组,表示我们想要获取的内容,匹配#后面的所有字符。
$ 表示行的结尾。

 
By 小鱼儿  阅读全文 | 回复(0) | 引用通告 | 编辑

发表评论:
 
Calendar

<<  < 2025 - >  >>
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30

Login


Bulletin
Recent Entries
Comments
Messages
Information
Links


Designed by Subdreamer
 
Powered by Oblog.