Negative look-behind
From: Bhargava (bhargava78_at_yahoo.com)
Date: 06/01/04
- Next message: Duncan Booth: "Re: Unification of Methods and Functions"
- Previous message: David Fraser: "Re: Will there be Function/class decorators in Python 2.4??"
- Next in thread: Josh Gilbert: "Re: Negative look-behind"
- Reply: Josh Gilbert: "Re: Negative look-behind"
- Reply: Paul McGuire: "Re: Negative look-behind"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 1 Jun 2004 02:14:54 -0700
Hello,
I am a newbie to python and need some help.
I am looking at doing some batch search/replace for some of my source
code. Criteria is to find all literal strings and wrap them up with
some macro, say MC. For ex., var = "somestring" would become var =
MC("somestring"). Literal strings can contain escaped " & \.
But there are 2 cases when this replace should not happen:
1.literal strings which have already been wrapped, like
MC("somestring")
2.directives like #include "header.h" and #extern "C".
I tried to use negative look-behind assertion for this purpose. The
expression I use for matching a literal string is
"((\\")|[^"(\\")])+". This works fine. But as I start prepending
look-behind patterns, things go wrong. The question I have is whether
the pattern in negative look-behind part can contain alternation ? In
other words can I make up a regexp which says "match this pattern x
only if it not preceded by anyone of pattern a, pattern b and pattern
c" ?
I tried the following expression to take into account the two
constraints mentioned above, (?<![(#include )(#extern
)(MC\()])"((\\")|[^"(\\")])+". Can someone point out the mistakes in
this ?
Thanks,
Bhargava
- Next message: Duncan Booth: "Re: Unification of Methods and Functions"
- Previous message: David Fraser: "Re: Will there be Function/class decorators in Python 2.4??"
- Next in thread: Josh Gilbert: "Re: Negative look-behind"
- Reply: Josh Gilbert: "Re: Negative look-behind"
- Reply: Paul McGuire: "Re: Negative look-behind"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|