使用通配符或正则表达式在字符串末尾查找空格 [英] Find whitespace in end of string using wildcards or regex
问题描述
我有一个 Resoure.resx 文件,我需要搜索以查找以空格结尾的字符串.我注意到在 Visual Web Developer 中,我可以使用正则表达式和通配符进行搜索,但我无法弄清楚如何最终只找到带有空格的字符串.我试过这个正则表达式但没有用:
I have a Resoure.resx file that I need to search to find strings ending with a whitespace. I have noticed that in Visual Web Developer I can search using both regex and wildcards but I can not figure out how to find only strings with whitespace in the end. I tried this regex but didn't work:
\s$
你能举个例子吗?谢谢!
Can you give me an example? Thanks!
推荐答案
我希望它可以工作,尽管因为 \s
包括 \n
和 \r
,也许它变得混乱了.或者我认为它可能(但真的不太可能)Visual Web Developer 使用的正则表达式的风格(我没有副本)没有 \s
字符类.试试这个:
I'd expect that to work, although since \s
includes \n
and \r
, perhaps it's getting confused. Or I suppose it's possible (but really unlikely) that the flavor of regular expressions that Visual Web Developer uses (I don't have a copy) doesn't have the \s
character class. Try this:
[ \f\t\v]$
...搜索行尾的空格、换页、制表符或垂直制表符.
...which searches for a space, formfeed, tab, or vertical tab at the end of a line.
如果您正在执行搜索和替换操作,并希望去掉行尾的所有空格,则 正如 RageZ 指出的,您需要包含一个贪婪的量词(+
表示一个或多个"),以便您尽可能多地获取:
If you're doing a search and replace and want to get rid of all of the whitespace at the end of the line, then as RageZ points out, you'll want to include a greedy quantifier (+
meaning "one or more") so that you grab as much as you can:
[ \f\t\v]+$
这篇关于使用通配符或正则表达式在字符串末尾查找空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!