[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: why is this regexp invalid: "\\(?1:\\)"
From: |
David Kastrup |
Subject: |
Re: why is this regexp invalid: "\\(?1:\\)" |
Date: |
Wed, 08 Dec 2010 15:27:16 -0000 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) |
pjb@informatimago.com (Pascal J. Bourguignon) writes:
> Joel James Adamson <adamsonj@email.unc.edu> writes:
>
>> Ilya Shlyakhter <ilya_shl@alum.mit.edu> writes:
>>
>>> (string-match "\\(?1:\\)" "")
>>> (string-match "\\(?:\\)" "")
>>
>> I get 0 from both.
>
> Which is expected. These regexps are not invalid, they're perfectly
> valid, and match perfectly what they have to match.
>
> Read (info "(elisp)Regexp Backslash").
>
> Notice that the two regexps have a different meaning.
>
> "\\(?1:\\)" matches exactly 0 characters, and assign them the group number 1.
>
> "\\(?:\\)" matches exactly 0 characters, if it can (it's shy), and
> assign them the next group number (which is 1 since it's the first
> group).
I recommend you check again what a shy group is supposed to be.
> In both case, when matching the empty string, the result should be 0,
> since there are 0 character at the position 0 in the empty string.
That much is correct.
--
David Kastrup