[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: why is this regexp invalid: "\\(?1:\\)"
From: |
Pascal J. Bourguignon |
Subject: |
Re: why is this regexp invalid: "\\(?1:\\)" |
Date: |
Wed, 08 Dec 2010 15:27:10 -0000 |
User-agent: |
Gnus/5.101 (Gnus v5.10.10) Emacs/23.2 (gnu/linux) |
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).
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.
--
__Pascal Bourguignon__ http://www.informatimago.com/