开发者

Find whitespace in end of string using wildcards or regex

开发者 https://www.devze.com 2023-01-30 11:01 出处:网络
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 b开发者_开发百科ut I

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 b开发者_开发百科ut 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!


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]+$


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

This would probably make it:

\s+$


Perhaps this would work:

^.+\s$

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号