Page 1 of 1

Regexp for adding a space

Posted: Tue Feb 08, 2005 7:26 pm
by dusan
Hi all,

I need to add a space in front of a colon : in hundreds of HTMLs, but I don't want to corrupt the links and tags that include a colon, therefore I created a list of keywords in front which the space can't be inserted.
size
family
language
align
http
ftp ....

I was thinking of an RegExp :

Search for: NOT(size|family|language|align|http|ftp):
Replace: \1 :

But I don't know how to insert "NOT" in the list of keywords :(
thank you

Re: Regexp for adding a space

Posted: Tue Feb 08, 2005 10:52 pm
by ben_josephs
You can't! Unfortunately, you can't search for text that doesn't match an arbitrary regular expression immediately preceding text that does match some other regular expression. The Boost regex library, which is what WildEdit uses, doesn't implement "look-behind assertions". (They are essentially difficult; even Perl's implementation is limited.)

But you can change the colons you want unchanged into something else that doesn't occur elsewhere in the text:
Change
(size|family|language|align|http|ftp):
to
$1¤
Then insert a space in front of each colon that remains:
Change
:
to
_:
(Use a space where I've put an underscore.)

Then recover the other colons:
Change
¤
to
:

Posted: Wed Feb 09, 2005 12:09 am
by dusan
Thank you ben_josephs for this tip. I didn't think about replacing it by something else :)
I think that sovled my problem.