Find spaces at the end of a string using wildcards or regular expressions

I have a Resoure.resx file that I need to find in order to find lines ending with a space. I noticed that in Visual Web Developer, I can search using both regular and wildcards, but I cannot figure out how to find only lines with spaces at the end. I tried this regex but didn't work:

\s$ 

Can you give me an example? Thanks!

+8
source share
4 answers

I expect this to work, though, since \s includes \n and \r , it may be confusing. Or I believe it is possible (but really unlikely) that the flavor of the regular expressions that Visual Web Developer uses (I don't have a copy) does not have the \s character class. Try the following:

 [ \f\t\v]$ 

... that searches at the end of a line for a space, form, tab, or vertical tab.

If you search and replace and want to get rid of all the spaces at the end of the line, then as RageZ indicates , you β€œI want to include the greedy quantifier ( + meansβ€œ one or more ”) so that you can capture as much as you can:

 [ \f\t\v]+$ 
+14
source
You were almost there. adding a + sign means 1 character to an infinite number of characters.

This will probably do this:

 \s+$ 
+7
source

Maybe this will work:

 ^.+\s$ 

Using this, you can find non-empty lines ending with a space character.

+1
source

You can try:

 your_string.endswith(" ") 

But, if you want to map any empty space, you can use:

 import re re.match(r".*\s$", your_string) 

The re.UNICODE flag can be useful if you are working with Python 2:

 import re re.match(r".*\s$", your_string, flags=re.UNICODE) 
0
source

All Articles