all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* why is this regexp invalid: "\\(?1:\\)"
@ 2010-09-01 19:40 Ilya Shlyakhter
  2010-09-02 18:27 ` Joel James Adamson
       [not found] ` <mailman.0.1283452083.4022.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 6+ messages in thread
From: Ilya Shlyakhter @ 2010-09-01 19:40 UTC (permalink / raw)
  To: help-gnu-emacs

dear emacs users,

can you help me understand why the following simple
expression gives an "Invalid regexp" error:

(string-match "\\(?1:\\)" "")

while removing the explicit group number gives no error:

(string-match "\\(?:\\)" "")

thanks,

ilya



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: why is this regexp invalid: "\\(?1:\\)"
       [not found] <mailman.2.1283370006.27482.help-gnu-emacs@gnu.org>
@ 2010-09-02  8:17 ` Stefan Monnier
  0 siblings, 0 replies; 6+ messages in thread
From: Stefan Monnier @ 2010-09-02  8:17 UTC (permalink / raw)
  To: help-gnu-emacs

> can you help me understand why the following simple
> expression gives an "Invalid regexp" error:

> (string-match "\\(?1:\\)" "")

> while removing the explicit group number gives no error:

> (string-match "\\(?:\\)" "")

My guess is that you're using a version of Emacs that is too old to
support explicit group numbers (which was a new feature in Emacs-23.1,
IIRC).


        Stefan


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: why is this regexp invalid: "\\(?1:\\)"
  2010-09-01 19:40 Ilya Shlyakhter
@ 2010-09-02 18:27 ` Joel James Adamson
       [not found] ` <mailman.0.1283452083.4022.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 6+ messages in thread
From: Joel James Adamson @ 2010-09-02 18:27 UTC (permalink / raw)
  To: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 345 bytes --]

Ilya Shlyakhter <ilya_shl@alum.mit.edu> writes:

> (string-match "\\(?1:\\)" "")
> (string-match "\\(?:\\)" "")

I get 0 from both.

Emacs version: GNU Emacs 24.0.50.3 (x86_64-unknown-linux-gnu, GTK+
Version 2.20.1) of 2010-08-31 on chondestes.bio.unc.edu

Joel

-- 
Joel J. Adamson
FSF Member #8164
http://www.unc.edu/~adamsonj

[-- Attachment #2: Type: application/pgp-signature, Size: 229 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: why is this regexp invalid: "\\(?1:\\)"
       [not found] ` <mailman.0.1283452083.4022.help-gnu-emacs@gnu.org>
@ 2010-09-02 20:15   ` Pascal J. Bourguignon
  2010-09-03  7:01     ` David Kastrup
  0 siblings, 1 reply; 6+ messages in thread
From: Pascal J. Bourguignon @ 2010-09-02 20:15 UTC (permalink / raw)
  To: help-gnu-emacs

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/


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: why is this regexp invalid: "\\(?1:\\)"
  2010-09-02 20:15   ` Pascal J. Bourguignon
@ 2010-09-03  7:01     ` David Kastrup
  2010-09-03 11:51       ` Pascal J. Bourguignon
  0 siblings, 1 reply; 6+ messages in thread
From: David Kastrup @ 2010-09-03  7:01 UTC (permalink / raw)
  To: help-gnu-emacs

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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: why is this regexp invalid: "\\(?1:\\)"
  2010-09-03  7:01     ` David Kastrup
@ 2010-09-03 11:51       ` Pascal J. Bourguignon
  0 siblings, 0 replies; 6+ messages in thread
From: Pascal J. Bourguignon @ 2010-09-03 11:51 UTC (permalink / raw)
  To: help-gnu-emacs

David Kastrup <dak@gnu.org> writes:

> 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.

Right.  I confounded it with non-greedy.

"\\(?:\\)" matches exactly 0 characters, and do not assign them to any
group number.


>> 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

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2010-09-03 11:51 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.2.1283370006.27482.help-gnu-emacs@gnu.org>
2010-09-02  8:17 ` why is this regexp invalid: "\\(?1:\\)" Stefan Monnier
2010-09-01 19:40 Ilya Shlyakhter
2010-09-02 18:27 ` Joel James Adamson
     [not found] ` <mailman.0.1283452083.4022.help-gnu-emacs@gnu.org>
2010-09-02 20:15   ` Pascal J. Bourguignon
2010-09-03  7:01     ` David Kastrup
2010-09-03 11:51       ` Pascal J. Bourguignon

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.