[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to highlight-regexp across multiple lines
From: |
Thorsten Jolitz |
Subject: |
Re: How to highlight-regexp across multiple lines |
Date: |
Thu, 03 Apr 2014 21:21:00 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) |
Angus Comber <anguscomber@gmail.com> writes:
> It seems that it matches the aPDU messages provided there is no 0 in the
> text. I am puzzled by the [^\\000] - where can I find documentation on it?
Thats stolen from the Org-mode sources, and I asked the same question
before ;)
Here is Carsten Dominik's answer:
,----------------------------------------------------------------------------
| > PS
| > Can anybody explain this marvelous construct in the regexp:
| >
| > ,---------
| > | [^\\000]
| > `---------
|
| This is just a cheep way to match any character at all, because \000 should
| not be part of any string (in C it indicates the end of a string).
| In principle you could put any character you are sure will not turn up,
| but \000 seems to be the safest choice. It is
| faster (I think) than "\\(.\\|\n\\)*" because the first will
| just run fast and streight with a table lookup while the
| latter need to always alternate between two alternatives.
| I have not timed it, though.
`----------------------------------------------------------------------------
> Is it not null or something like that? But then why does it not capture
> string "0"?
This happened to me to, although I think it shouldn't.
But when I used it with M-x regexp-builder it worked. With M-x reb-copy
(and then paste), the [^\\000] is transformed to a different
representation - maybe you could try reb-copy & paste it into your
function and see if it works then?
> On 3 April 2014 16:08, Thorsten Jolitz <tjolitz@gmail.com> wrote:
>
>> Angus Comber <anguscomber@gmail.com> writes:
>>
>> > I was looking at this question on stackoverflow and it seems regex can
>> > select across multiple lines generally but how would I do so for
>> > highlight-regexp in emacs?
>> >
>> >
>> http://stackoverflow.com/questions/159118/how-do-i-match-any-character-across-multiple-lines-in-a-regular-expression
>> >
>> >
>> > Eg I want to highlight ALL text from aPDU... to the final closing brace:
>> >
>> > aPDU-rose : retResult : {
>> > invokeID 2,
>> > operValue {
>> > operationValue local : 71,
>> > result {
>> > crossRefIdentifier '40 3f'H
>> > }
>> > }
>> > }
>> >
>> >
>> > How would I do that using highlight-regexp?
>> >
>> > highlight-regexp aPDU-rose.* hi-yellow would get me the first line - but
>> > how to get everything including last } character?
>>
>> This regexp did match the aPDU in the gnus *Article* buffer:
>>
>> ,--------------------
>> | "^aPDU[^\\000]+[}]+?$"
>> `--------------------
>>
>> --
>> cheers,
>> Thorsten
>>
>>
>>
>
--
cheers,
Thorsten
Re: How to highlight-regexp across multiple lines, Nicolas Richard, 2014/04/04