home | list info | list archive | date index | thread index

[OCLUG-Tech] Perl regex problem

I have run into one of those Perl regular expression problems that seemed not-too-complicated when I first looked at it but right now it has me somewhat stumped.

I want to do a systematic search and replace of a word only where the word is NOT enclosed in double quotations.

That is, I want to substitute "foo" with "bar" so that e.g.

  "cat foo dog" foo "pig foo chicken"

becomes

 "cat foo dog" bar "pig foo chicken"

The quoted text can be anywhere in the string.

Apparently there is no easy way of doing this in one expression. :P

Am I missing something obvious here? I would think that this problem must come up all the time?

replies

message navigation