正则表达式替换的妙用 #2
JasonGrass
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
默认的重命名规则,可能无法满足一些特殊的需求,通常都可以用正则表达式试试,这里记录遇到的场景。
提取并移动字符串
将
春晚看中国!回到最开始!【难忘今朝1983】
变成【难忘今朝1983】春晚看中国!回到最开始!
正则表达式为
/^(.*?)(【难忘今朝\d\d\d\d】)(.*)$/
新字符串为
$2$1$3
这里使用的是正则表达式中的提取组和反向引用功能
删除指定字符串前后的字符串
将
123 456 .abc
中,.abc
前面的空格删除正则表达式:
/\s*(\.abc)/
新字符串:
$1
意思就是,匹配原字符串中
.abc
这部分,并将其替换成.abc
,就达到了删除空格的目的正则表达式30分钟入门教程
Beta Was this translation helpful? Give feedback.
All reactions