Charlie Mulic
Charlie Mulic

Reputation: 199

Regex -- replace all spaces before a particular character

The goal is to make something like

This is some text=This is some text

become:

This\ is\ some\ text=This is some text

I've been playing with variations of things I know will grab spaces/whitespaces (like "\ " or \s) in front of (?==) which seems to select until the = character, but nothing seems to be working in Intellij IDEA's search and replace.

Any suggestions?

Upvotes: 2

Views: 1455

Answers (1)

DreadPirateShawn
DreadPirateShawn

Reputation: 8412

Copying the answer from the comments in order to remove this question from the "Unanswered" filter:

This - (\s)(?=.*=) should work. Replace it with \$1

~ answer per Rohit Jain

This was additionally confirmed by the OP:

That worked, though I used a literal space instead of the \s because it was picking up some additional white space I didn't want replaced. Also had to do some silly escaping for the replace (\\$1 )

Upvotes: 2

Related Questions