[CentralOH] Regex Question
Nick Albright
nick.albright at gmail.com
Tue Sep 30 14:44:17 CEST 2014
Along those lines, you might try changing the first [^!#] to
[^!#\s]
so it won't match a whitespace character.
On Mon, Sep 29, 2014 at 11:35 AM, Len Jaffe <lenjaffe at jaffesystems.com>
wrote:
> [^!#] 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.
>
>
> _______________________________________________
> 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/7af00601/attachment.html>
More information about the CentralOH
mailing list