perl regular expressions . . . .
perl regular expressions . . . .
Author
Discussion

Code Monkey

Original Poster:

3,318 posts

288 months

Monday 30th July 2007
quotequote all
I am curently trying to compress files, aiming to reduce the file size even to the point of reducing whitespace.

$data3=~ s/\s+=\s+/=/g;

The above line is working nicely except for when i have text within strings that I dont want to be affected, has anyone written a regular expression that will leave alone all the text in strings while still reducing the rest of the code.
ie.

if the line is first
var a = 10;
var b = "This value = "+a);

I would like after compression to get
var a=10;
var b="This value = "+a);

Any further pointers would also be useful, currently working my way through all the perl websites and plenty of info but after bit sized chunks to kick off.

Cheers

cottonfoo

6,053 posts

241 months

Tuesday 31st July 2007
quotequote all
It isn't trivial but not too hard. Are all your strings delimited the same way?

What are you actually trying to do? There may be a better way using something like Compress::Zlib.

Edited by cottonfoo on Tuesday 31st July 15:22