[CentralOH] Regex Question
John Cassidy
jocassid at gmail.com
Tue Sep 30 07:36:17 CEST 2014
based on what you're looking for processing the data (i assume it's in a
file) line by line might be easier to code than coming up with a regex
On Sep 29, 2014 10:46 AM, "Joshua Kramer" <joskra42.list at gmail.com> wrote:
> 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
>
> _______________________________________________
> CentralOH mailing list
> CentralOH at python.org
> https://mail.python.org/mailman/listinfo/centraloh
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/centraloh/attachments/20140930/0f1b21fa/attachment.html>
More information about the CentralOH
mailing list