Help with using regular expressions in find & replace


#1

I used AS3toHX to convert actionscript code to hexe code, My main problem with it is that it removes a lot of spaces which I want to restore.

For example I want to replace the = in x=3 with " = " to give x = 3.

Using \w=\w in Find will find all case of an = bracketed by alphanumeric characters.

What do I enter in Replace so that only the = is replaced, not the characters bracketing it?

Thanks in advance!


#2

Have you tried capturing those characters?
(\w)=(\w)
$1 = $2
?


#3

That worked thanks. Didn’t know about capturing characters.


#4

You can capture any group: for example if you wanted to capture all of those things:

a =b;
a= b;
a=b;

You can use
(\w ?)=( ?\w) (character + optional space)=(optional space + character)
$1 = $2


#5

Sorry that doesn’t work. For a =b and a= b, single spaces become double spaces.


#6

Yeah, you don’t want to capture the space. Search for this instead: (\w) ?= ?(\w)