Finding strings with exceptions
David Brady
daves_spam_dodging_account at yahoo.com
Mon Dec 3 12:47:43 EST 2001
More information about the Python-list mailing list
Mon Dec 3 12:47:43 EST 2001
- Previous message (by thread): Finding strings with exceptions
- Next message (by thread): Finding strings with exceptions
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Hello, I'm trying to grep through a project, and I've come across this problem many times in the past. Previously, doing this problem in perl, I've just given up because my perl regex skill is "merely competent" and not wizardly. Today I ran into the same problem, and since Python has amazed me countless times already, I figured that it might be possible. What I want to do is find all instances of an expression EXCEPT those that also match another expression. The case in point for today was this: I was called away from my machine in the middle of refactoring some code. I was renaming a class to conform to our project's coding standards, and the new name requires a prefix. The old class name (changed to protect the innocent) is BarThingy. The new name is fooBarThingy. Because the new class name contains the old one, simple find-and-replace goes wonky. In the reverse case, I could put something in the regex that says, "also find an optional prefix 'foo'." But what I really want to do is find the class everywhere EXCEPT where that 'foo' prefix exists. Anyone know a good way to do this? Note that one cannot simply grep all the lines that contain BarThingy and then remove lines that contain fooBarThingy, because a single line might contain both. Hmm, in writing this, I wonder if I could look for foo as an optional group, and call a function that causes the regex to fail if the group is present... hmmmm.... Thanks, -dB ===== David Brady daves_spam_dodging_account at yahoo.com I'm feeling very surreal today... or *AM* I? __________________________________________________ Do You Yahoo!? Buy the perfect holiday gifts at Yahoo! Shopping. http://shopping.yahoo.com
- Previous message (by thread): Finding strings with exceptions
- Next message (by thread): Finding strings with exceptions
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list