使用通配符或正则表达式查找字符串末尾的空格

发布于 2024-10-07 16:10:03 字数 188 浏览 1 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

无法回应 2024-10-14 16:10:04

我希望它能起作用,尽管由于 \s 包含 \n\r,也许它会变得混乱。或者我认为 Visual Web Developer 使用的正则表达式风格(我没有副本)可能(但真的不太可能)没有 < code>\s 字符类。试试这个:

[ \f\t\v]$

...它在行尾搜索空格、换页符、制表符或垂直制表符。

如果您正在进行搜索和替换,并且想要删除行尾的所有空格,那么 正如 RageZ 指出的,你需要包含一个贪婪量词(+ 表示“一个或多个”),以便你能获取尽可能多的东西:

[ \f\t\v]+$

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.

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]+$
长亭外,古道边 2024-10-14 16:10:04

你就快到了。添加 + 符号表示 1 个字符到无限个字符。

这可能会做到:

\s+$

You were almost there. adding the + sign means 1 characters to infinite number of characters.

This would probably make it:

\s+$
眼趣 2024-10-14 16:10:04

也许这会起作用:

^.+\s$

使用它,您将能够找到以空白字符结尾的非空行。

Perhaps this would work:

^.+\s$

Using this you'll be able to find nonempty lines that end with a whitespace character.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文