Remove white spaces using regular expression [t ]+

The correct expression to remove white spaces using regular expression is

[t ]+ — Make sure  you select Regular Expression in Search Criteria

I used the following which id not quite work [t ]*. The problem with this one is it match 0 or more. So it basically matche every single character rather than matches spaces only. Hope this helps somebody.

 

It is also a good practice, instead of complete removing white spaces, replace it by a single space as your code might not work if you remove all spaces. The search critera also remove tab characters.

Some variotions

^[t ]+ =  Will match white spaces that are in the beginning of each line

[t ]+$ = will match white spaces that are at the end of each line

 

Advertisements
This entry was posted in Regular Expressions. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s