使用通配符或正则表达式查找字符串末尾的空格
我有一个 Resoure.resx 文件,需要搜索该文件以查找以空格结尾的字符串。我注意到,在 Visual Web Developer 中,我可以使用正则表达式和通配符进行搜索,但我无法弄清楚如何仅查找最后带有空格的字符串。我尝试了这个正则表达式但没有用:
\s$
你能给我一个例子吗?谢谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我希望它能起作用,尽管由于
\s
包含\n
和\r
,也许它会变得混乱。或者我认为 Visual Web Developer 使用的正则表达式风格(我没有副本)可能(但真的不太可能)没有 < code>\s 字符类。试试这个:...它在行尾搜索空格、换页符、制表符或垂直制表符。
如果您正在进行搜索和替换,并且想要删除行尾的所有空格,那么 正如 RageZ 指出的,你需要包含一个贪婪量词(
+
表示“一个或多个”),以便你能获取尽可能多的东西: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:...which searches for a space, formfeed, tab, or vertical tab at the end of a line.
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:你就快到了。添加
+
符号表示 1 个字符到无限个字符。这可能会做到:
You were almost there. adding the
+
sign means 1 characters to infinite number of characters.This would probably make it:
也许这会起作用:
使用它,您将能够找到以空白字符结尾的非空行。
Perhaps this would work:
Using this you'll be able to find nonempty lines that end with a whitespace character.