user4368069
user4368069

Reputation:

Adding space after symbol if there doesn't already exist a space?

I need to replace all instances of commas in my file where there isn't already a space after the comma.

For example, the following needs to change. From this:

some function(int x,int y, int z)
{
    // code
}

To this:

some function(int x, int y, int z)
{
    // code
}

Notice the spaces after the commas where there wasn't already a space. How can I do this to apply to a 1,000+ line file of code using Sublime?

Upvotes: 1

Views: 513

Answers (1)

hwnd
hwnd

Reputation: 70732

Use Ctrl + H to open the Search and Replace, enable Regular Expression..

Using Negative Lookahead:

Find: ,(?!\s)
Replace: , 
          ^
          |___ space character

Or a basic regular expression:

Find: ,([^\s])
Replace: , \1

Upvotes: 3

Related Questions