[texworks] Regex challenges

Jonathan Kew jfkthame at googlemail.com
Fri Apr 10 16:38:45 CEST 2009


On 10 Apr 2009, at 15:28, Stefan Löffler wrote:

> On 2009-04-10 16:00, Joseph Wright wrote:
>>>> 2) In a DTX, comments in the explanation part start ^^A. This is  
>>>> easy to
>>>> match with \^\^A, but that matches even in the code blocks.   
>>>> Ideally,
>>>> I'd like:
>>>> - If the line start %, comment = ^^A
>>>> - If the line starts without %, comment = %
>>>> but only colouring from the start of the comment, not the start  
>>>> of the
>>>> line.  Is this doable at all?
>>>>
>>> I can't think of a way to do this.
>>>
>>
>> Ah well: I just wanted to be sure I'd not missed anything obvious.
>>
>
> I guess this could be achieved by lookbehind assertions (?<=...). I'm
> not sure if they are supported by QRegExp, however (lookahead  
> assertions
> are explicitly mentioned in the documentation, but lookbehind  
> assertions
> are simply omitted). You'd have to try it out to see if it works.  
> Maybe
> something like
> (?<=\n%.*)^^A.*
> (Note: This will fail on the first line (since it doesn't start with a
> \n) and may have other flaws. But it could get you started)

I wondered about this, but even in Perl regexes, lookbehind assertions  
are fixed-length only, so it wouldn't work.

JK



More information about the texworks mailing list