用于删除字符串末尾字符的正则表达式 [英] regex for removing characters at end of string
问题描述
我想递归匹配所有以 :
或 /
或 ;
或 ,
结尾的文本并删除所有这些字符,以及文本末尾留下的任何空格.
i would like to match recursively, all text that ends with :
or /
or ;
or ,
and remove all these characters, along with any spaces left behind, in the end of the text.
示例:
some text : ; , /
应该变成:
some text
我尝试过的只是删除找到的任何这些特殊字符的第一次出现,如何递归地执行此操作,以便删除所有字符找到那场比赛了吗?我使用的正则表达式:
What i have tried, just removes the first occurrence of any of these special characters found, how one can do this recursively, so as to delete all characters found that match? regex i use:
查找:[ ,;:/]*
什么都没有替换
推荐答案
[ ,;:/]*$
应该是你所需要的.这与您当前的正则表达式相同,只是末尾带有 $
.$
告诉它匹配必须发生在字符串的末尾.
[ ,;:/]*$
should be what you need. This is the same as your current regex except with the $
on the end. The $
tells it that the match must happen at the end of the string.
这篇关于用于删除字符串末尾字符的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!