[CentralOH] Regex Question

Joshua Kramer joskra42.list at gmail.com
Mon Sep 29 16:46:32 CEST 2014


Hello All,

I have an interesting challenge with a regex.  I need to match any line
that:
    Does not contain a !  or a # as the first non-whitespace character
    Contains the word 'if', but not the string "-if" or the string "ifdef"

So this should match:

"    if a=1 then"

These should not match:

"!* If this code runs..."
"#ifdef something"
"    !If this code runs..."

Here's the regex I have so far:

^\s*[^!#].*[^-]if[^a-zA-Z0-9_].*

This works for the most part, except it is matching lines that begin with
any number of whitespaces and an exclamation point.  So it incorrectly
matches this, for example:

"      ! if you have a comment..."


This is undesired behavior.

What am I missing here?

Thanks!
-JK
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/centraloh/attachments/20140929/7a53d861/attachment.html>


More information about the CentralOH mailing list