* regexp problems the evil \[
@ 2017-03-23 21:57 Uwe Brauer
2017-03-23 22:05 ` Stefan Monnier
0 siblings, 1 reply; 8+ messages in thread
From: Uwe Brauer @ 2017-03-23 21:57 UTC (permalink / raw)
To: help-gnu-emacs
Hi
The following drives me crazy
(query-replace "\\[" "\\begin{displaymath}\n" nil)
Replaces
\[
by
\begin{displaymath}
But
(query-replace-regexp "\\[\\([^}]+\\)\\]" "@\\1" nil))
Does not replace
\[eq:testpandoc:1\]
By @eq:testpandoc:1
What do I miss?
Thanks
Uwe Brauer
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: regexp problems the evil \[
2017-03-23 21:57 regexp problems the evil \[ Uwe Brauer
@ 2017-03-23 22:05 ` Stefan Monnier
2017-03-23 22:11 ` Uwe Brauer
0 siblings, 1 reply; 8+ messages in thread
From: Stefan Monnier @ 2017-03-23 22:05 UTC (permalink / raw)
To: help-gnu-emacs
> (query-replace "\\[" "\\begin{displaymath}\n" nil)
^^^^^^^^^^^^^^^^^^^
matches \[
> (query-replace-regexp "\\[\\([^}]+\\)\\]" "@\\1" nil))
^^^^^^^^^^^^^^^^^^^^^^^^^
matches [
Since [ in regexps has otherwise a special meaning.
To match \[ and \] you'll want
(query-replace-regexp "\\\\\\[\\([^}]+\\)\\\\\\]" "@\\1" nil))
-- Stefan
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: regexp problems the evil \[
2017-03-23 22:05 ` Stefan Monnier
@ 2017-03-23 22:11 ` Uwe Brauer
2017-03-23 23:38 ` Aurélien Aptel
2017-03-24 2:27 ` Stefan Monnier
0 siblings, 2 replies; 8+ messages in thread
From: Uwe Brauer @ 2017-03-23 22:11 UTC (permalink / raw)
To: help-gnu-emacs
>>> "Stefan" == Stefan Monnier <monnier@iro.umontreal.ca> writes:
>> (query-replace "\\[" "\\begin{displaymath}\n" nil)
> ^^^^^^^^^^^^^^^^^^^
> matches \[
>> (query-replace-regexp "\\[\\([^}]+\\)\\]" "@\\1" nil))
> ^^^^^^^^^^^^^^^^^^^^^^^^^
> matches [
> Since [ in regexps has otherwise a special meaning.
> To match \[ and \] you'll want
> (query-replace-regexp "\\\\\\[\\([^}]+\\)\\\\\\]" "@\\1" nil))
Wow six \ I gave up after five.
Thanks
Uwe
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: regexp problems the evil \[
2017-03-23 22:11 ` Uwe Brauer
@ 2017-03-23 23:38 ` Aurélien Aptel
2017-03-24 0:38 ` hector
2017-03-24 17:07 ` Uwe Brauer
2017-03-24 2:27 ` Stefan Monnier
1 sibling, 2 replies; 8+ messages in thread
From: Aurélien Aptel @ 2017-03-23 23:38 UTC (permalink / raw)
To: help-gnu-emacs@gnu.org
On Thu, Mar 23, 2017 at 11:11 PM, Uwe Brauer <oub@mat.ucm.es> wrote:
> Wow six \ I gave up after five.
Yes, it's ridiculous, I personally think emacs lisp regexes are
unusable once escapes are involved, especially interactively.
You can use rx instead of strings to make regexes from s-expressions.
Strings elements are always assumed to match literally (rx will always
escape whatever is needed to match the string literally).
(query-replace-regexp (rx "\\[" (group (+ (not (any "}")))) "\\]") ...
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: regexp problems the evil \[
2017-03-23 23:38 ` Aurélien Aptel
@ 2017-03-24 0:38 ` hector
2017-03-24 17:07 ` Uwe Brauer
2017-03-24 17:07 ` Uwe Brauer
1 sibling, 1 reply; 8+ messages in thread
From: hector @ 2017-03-24 0:38 UTC (permalink / raw)
To: help-gnu-emacs
On Fri, Mar 24, 2017 at 12:38:18AM +0100, Aurélien Aptel wrote:
> On Thu, Mar 23, 2017 at 11:11 PM, Uwe Brauer <oub@mat.ucm.es> wrote:
> > Wow six \ I gave up after five.
>
> Yes, it's ridiculous, I personally think emacs lisp regexes are
> unusable once escapes are involved, especially interactively.
It's not so serious. Easy:
escape *2
text ---> regexp ---> lisp
\[ \\\[ \\\\\\[
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: regexp problems the evil \[
2017-03-24 0:38 ` hector
@ 2017-03-24 17:07 ` Uwe Brauer
0 siblings, 0 replies; 8+ messages in thread
From: Uwe Brauer @ 2017-03-24 17:07 UTC (permalink / raw)
To: help-gnu-emacs
>>> "hector" == hector <hectorlahoz@gmail.com> writes:
> On Fri, Mar 24, 2017 at 12:38:18AM +0100, Aurélien Aptel wrote:
>> On Thu, Mar 23, 2017 at 11:11 PM, Uwe Brauer <oub@mat.ucm.es> wrote:
>> > Wow six \ I gave up after five.
>>
>> Yes, it's ridiculous, I personally think emacs lisp regexes are
>> unusable once escapes are involved, especially interactively.
> It's not so serious. Easy:
> escape *2
> text ---> regexp ---> lisp
> \[ \\\[ \\\\\\[
But you must confess that it is a bit counter intuitive, no?
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: regexp problems the evil \[
2017-03-23 23:38 ` Aurélien Aptel
2017-03-24 0:38 ` hector
@ 2017-03-24 17:07 ` Uwe Brauer
1 sibling, 0 replies; 8+ messages in thread
From: Uwe Brauer @ 2017-03-24 17:07 UTC (permalink / raw)
To: help-gnu-emacs
>>> "Aurélien" == Aurélien Aptel <aurelien.aptel+emacs@gmail.com> writes:
> On Thu, Mar 23, 2017 at 11:11 PM, Uwe Brauer <oub@mat.ucm.es> wrote:
>> Wow six \ I gave up after five.
> Yes, it's ridiculous, I personally think emacs lisp regexes are
> unusable once escapes are involved, especially interactively.
> You can use rx instead of strings to make regexes from s-expressions.
> Strings elements are always assumed to match literally (rx will always
> escape whatever is needed to match the string literally).
> (query-replace-regexp (rx "\\[" (group (+ (not (any "}")))) "\\]") ...
Ah thanks did not know about it.
Uwe
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: regexp problems the evil \[
2017-03-23 22:11 ` Uwe Brauer
2017-03-23 23:38 ` Aurélien Aptel
@ 2017-03-24 2:27 ` Stefan Monnier
1 sibling, 0 replies; 8+ messages in thread
From: Stefan Monnier @ 2017-03-24 2:27 UTC (permalink / raw)
To: help-gnu-emacs
> Wow six \ I gave up after five.
Next exercise: write a regexp that matches this regexp.
Stefan
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2017-03-24 17:07 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-03-23 21:57 regexp problems the evil \[ Uwe Brauer
2017-03-23 22:05 ` Stefan Monnier
2017-03-23 22:11 ` Uwe Brauer
2017-03-23 23:38 ` Aurélien Aptel
2017-03-24 0:38 ` hector
2017-03-24 17:07 ` Uwe Brauer
2017-03-24 17:07 ` Uwe Brauer
2017-03-24 2:27 ` Stefan Monnier
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).