Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find whitespace in end of string using wildcards or regex

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!

like image 639
Martin Avatar asked Dec 15 '10 09:12

Martin


People also ask

How do you find a space in a string in regex?

Spaces can be found simply by putting a space character in your regex. Whitespace can be found with \s . If you want to find whitespace between words, use the \b word boundary marker.

Can you use wildcard in regex?

Resolution. To use 'regexp' syntax, you must use a / (slash) at the beginning and end of the regexp. To wildcard text at the beginning and ending of the line, add a ". *" (dot asterisk) to the beginning and end of the 'Actor Command Line'.

How do I match a character except space in regex?

You can match a space character with just the space character; [^ ] matches anything but a space character.

Are wildcards and regex the same?

Wildcards are different from the regular expressions used in grep (although they may look similar at times). Wildcards apply to all commands including grep and are used in place of or in combination with operands. Regular Expressions only apply to grep and a few other UNIX commands.


2 Answers

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]+$
like image 105
T.J. Crowder Avatar answered Sep 21 '22 17:09

T.J. Crowder


Perhaps this would work:

^.+\s$

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

like image 22
darioo Avatar answered Sep 23 '22 17:09

darioo