匹配正则表达式并反转目标字符串中的匹配
基于这个问题正则表达式\d+(?:-\d+)+
将匹配 10-3-1
和 5-0
。
示例:
This is 10-3-1 my string
执行匹配和反转后,我希望它是这样的:
This is 1-3-10 my string
请注意,10-3-1 应该变成 1-3-10,而不是正常的字符串反转,这会导致 1-3-01。
Based on this question Regex \d+(?:-\d+)+
will match this 10-3-1
and 5-0
.
Example:
This is 10-3-1 my string
After performing the matching and reversing, I want it to be like this:
This is 1-3-10 my string
Notice that 10-3-1 should become 1-3-10 and not normal string reverse which would result in 1-3-01.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
基本算法是:
"10-3-1"
["10","3","1"]
["1","3","10"]
"1-3-10"
A basic algorithm would be:
"10-3-1"
["10","3","1"]
["1","3","10"]
"1-3-10"
尽管这里回答的问题是一段稍微修改了正则表达式的代码:
Although the question was answered here is a piece of code with a slightly modified regex: