unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Regular expression grouping not working?
@ 2020-02-08 19:17 Douglas Lewan
  2020-02-08 19:30 ` Teemu Likonen
  0 siblings, 1 reply; 4+ messages in thread
From: Douglas Lewan @ 2020-02-08 19:17 UTC (permalink / raw)
  To: help-gnu-emacs

I'm writing some code that includes the regular expression \\([^/]+/\\), 
(looking for a path on GNU/Linux) which doesn't match what I expect it 
should.

On the other hand, the regular expression [^/]+/, exactly the regular 
expression within the first, does match.

That seems wrong somehow. Is there something I'm missing?

-- 
,Doug
d.lewan2000@gmail.com
(908) 720 7908

Isn't there a difference between "acquittal" and "exoneration"?




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

* Re: Regular expression grouping not working?
  2020-02-08 19:17 Regular expression grouping not working? Douglas Lewan
@ 2020-02-08 19:30 ` Teemu Likonen
  2020-02-08 19:48   ` Douglas Lewan
  0 siblings, 1 reply; 4+ messages in thread
From: Teemu Likonen @ 2020-02-08 19:30 UTC (permalink / raw)
  To: Douglas Lewan, help-gnu-emacs

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

Douglas Lewan [2020-02-08T14:17:54-05] wrote:

> I'm writing some code that includes the regular expression \\([^/]+/\\), 
> (looking for a path on GNU/Linux) which doesn't match what I expect it 
> should.

Maybe your backslash escaping is wrong. In regular expressions the
grouping is made with \( \) but within Lisp strings backslash has a
special meaning too and those must be escaped "\\( \\)".

> Is there something I'm missing?

I think we need more information about your code and input data.

-- 
///  OpenPGP key: 4E1055DC84E9DFF613D78557719D69D324539450
//  https://keys.openpgp.org/search?q=tlikonen@iki.fi
/  https://keybase.io/tlikonen  https://github.com/tlikonen

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 694 bytes --]

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

* Re: Regular expression grouping not working?
  2020-02-08 19:30 ` Teemu Likonen
@ 2020-02-08 19:48   ` Douglas Lewan
  2020-02-17  0:15     ` Göktuğ Kayaalp
  0 siblings, 1 reply; 4+ messages in thread
From: Douglas Lewan @ 2020-02-08 19:48 UTC (permalink / raw)
  To: Teemu Likonen, help-gnu-emacs

On 2/8/20 2:30 PM, Teemu Likonen wrote:

> Douglas Lewan [2020-02-08T14:17:54-05] wrote:
>
>> I'm writing some code that includes the regular expression \\([^/]+/\\),
>> (looking for a path on GNU/Linux) which doesn't match what I expect it
>> should.
> Maybe your backslash escaping is wrong. In regular expressions the
> grouping is made with \( \) but within Lisp strings backslash has a
> special meaning too and those must be escaped "\\( \\)".

Damn! I was passing the double slash to a command I use to help me debug 
regular expressions.

Hand it the right string and it matches just as expected. (Too much 
kill-and-yank.)

Maybe now I can track down the real bug.

Thanks for helping me change my perspective.

>> Is there something I'm missing?
> I think we need more information about your code and input data.

-- 
,Doug
d.lewan2000@gmail.com
(908) 720 7908

Isn't there a difference between "acquittal" and "exoneration"?




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

* Re: Regular expression grouping not working?
  2020-02-08 19:48   ` Douglas Lewan
@ 2020-02-17  0:15     ` Göktuğ Kayaalp
  0 siblings, 0 replies; 4+ messages in thread
From: Göktuğ Kayaalp @ 2020-02-17  0:15 UTC (permalink / raw)
  To: help-gnu-emacs

FWIW, you might want to try rx for your regular expressions. It
generates regexes from a readable sexp syntax, and is included in Emacs
proper. It's way easier to modify and reason.  See "(elisp) Rx
Notation".




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

end of thread, other threads:[~2020-02-17  0:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-02-08 19:17 Regular expression grouping not working? Douglas Lewan
2020-02-08 19:30 ` Teemu Likonen
2020-02-08 19:48   ` Douglas Lewan
2020-02-17  0:15     ` Göktuğ Kayaalp

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).