[CentralOH] Regex Question
Len Jaffe
lenjaffe at jaffesystems.com
Mon Sep 29 17:35:37 CEST 2014
[^!#] will match whitespace, as will .*.
You're probably going to need to delve into zero-width look-aheads and
look-behinds.
On Mon, Sep 29, 2014 at 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
>
>
--
Len Jaffe - Information Technology Smoke Jumper - lenjaffe at jaffesystems.com
614-404-4214 @LenJaffe <https://www.twitter.com/lenJaffe>
www.lenjaffe.com
Host of Columbus Code Jam <http://www.meetup.com/techlifecolumbus/> -
@CodeJamCMH <https://www.twitter.com/CodeJamCMH>
Advent Planet <http://www.lenjaffe.com/AdventPlanet/> - An Aggregation of
Online Advent Calendars.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/centraloh/attachments/20140929/0dadab4f/attachment.html>
More information about the CentralOH
mailing list