* Negate a regexp
@ 2010-04-19 14:57 Leo
2010-04-19 15:51 ` Drew Adams
0 siblings, 1 reply; 7+ messages in thread
From: Leo @ 2010-04-19 14:57 UTC (permalink / raw)
To: help-gnu-emacs
Hello all,
How to negate a regexp? For example this one: \(?:\sw\|\s_\|\s\\).
Thank you.
Leo
^ permalink raw reply [flat|nested] 7+ messages in thread
* RE: Negate a regexp
2010-04-19 14:57 Negate a regexp Leo
@ 2010-04-19 15:51 ` Drew Adams
2010-04-19 17:32 ` Leo
0 siblings, 1 reply; 7+ messages in thread
From: Drew Adams @ 2010-04-19 15:51 UTC (permalink / raw)
To: 'Leo', help-gnu-emacs
> How to negate a regexp? For example this one: \(?:\sw\|\s_\|\s\\).
You cannot express a complement using (real) regexps. Regular expressions are
just not that expressive (powerful).
However, Emacs Lisp is that powerful; its use of regexps is not limited to real
regular expressions; and you can bathe your use of regexps in a more powerful
sauce.
In Emacs Lisp, you can in some cases use complementary syntax: \W as complement
of \w, \S_ as complement of \s_, etc. And you can use ^ at the beginning of a
[...] character set to complement that set (what the manual calls a
"complemented character alternative"). See node `Syntax of Regexps' in the Elisp
manual.
Another thing you can do is to use a regexp to determine a set of matches -
those elements you do not want, and then, assuming you know the overall domain
explicitly (extensively), subtract those matches to get the complement (those
elements of the domain that do not match).
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Negate a regexp
2010-04-19 15:51 ` Drew Adams
@ 2010-04-19 17:32 ` Leo
2010-04-19 17:54 ` Thierry Volpiatto
0 siblings, 1 reply; 7+ messages in thread
From: Leo @ 2010-04-19 17:32 UTC (permalink / raw)
To: help-gnu-emacs
On 2010-04-19 16:51 +0100, Drew Adams wrote:
>> How to negate a regexp? For example this one: \(?:\sw\|\s_\|\s\\).
>
> You cannot express a complement using (real) regexps. Regular expressions are
> just not that expressive (powerful).
>
> However, Emacs Lisp is that powerful; its use of regexps is not limited to real
> regular expressions; and you can bathe your use of regexps in a more powerful
> sauce.
>
> In Emacs Lisp, you can in some cases use complementary syntax: \W as complement
> of \w, \S_ as complement of \s_, etc. And you can use ^ at the beginning of a
> [...] character set to complement that set (what the manual calls a
> "complemented character alternative"). See node `Syntax of Regexps' in the Elisp
> manual.
>
> Another thing you can do is to use a regexp to determine a set of matches -
> those elements you do not want, and then, assuming you know the overall domain
> explicitly (extensively), subtract those matches to get the complement (those
> elements of the domain that do not match).
I need to provide a regexp to an abbrev table so that the match in group
1 (which is the abbrev name) can contain word symbol or \. The match is
done through (looking-back ...) with the GREEDY arg omitted. For example
in a buffer with text \coor-!-, where -!- indicates point, (looking-back
REGEXP) (match-string 1) should return \coor. Any idea how to construct
such a REGEXP?
I am not entirely sure the way the :regexp to abbrev table should be
provided is well thought-out. See my question to emacs-devel:
http://permalink.gmane.org/gmane.emacs.devel/123749.
Cheers,
Leo
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Negate a regexp
2010-04-19 17:32 ` Leo
@ 2010-04-19 17:54 ` Thierry Volpiatto
2010-04-19 18:35 ` Leo
0 siblings, 1 reply; 7+ messages in thread
From: Thierry Volpiatto @ 2010-04-19 17:54 UTC (permalink / raw)
To: help-gnu-emacs
Leo <sdl.web@gmail.com> writes:
> On 2010-04-19 16:51 +0100, Drew Adams wrote:
>>> How to negate a regexp? For example this one: \(?:\sw\|\s_\|\s\\).
>>
>> You cannot express a complement using (real) regexps. Regular expressions are
>> just not that expressive (powerful).
>>
>> However, Emacs Lisp is that powerful; its use of regexps is not limited to real
>> regular expressions; and you can bathe your use of regexps in a more powerful
>> sauce.
>>
>> In Emacs Lisp, you can in some cases use complementary syntax: \W as complement
>> of \w, \S_ as complement of \s_, etc. And you can use ^ at the beginning of a
>> [...] character set to complement that set (what the manual calls a
>> "complemented character alternative"). See node `Syntax of Regexps' in the Elisp
>> manual.
>>
>> Another thing you can do is to use a regexp to determine a set of matches -
>> those elements you do not want, and then, assuming you know the overall domain
>> explicitly (extensively), subtract those matches to get the complement (those
>> elements of the domain that do not match).
>
> I need to provide a regexp to an abbrev table so that the match in group
> 1 (which is the abbrev name) can contain word symbol or \. The match is
> done through (looking-back ...) with the GREEDY arg omitted. For example
> in a buffer with text \coor-!-, where -!- indicates point, (looking-back
> REGEXP) (match-string 1) should return \coor. Any idea how to construct
> such a REGEXP?
It will return \\coor because \ have to be escaped.
(save-excursion (when (looking-back "^\\(\\\\[a-z]*\\)") (match-string 0)))
It match on 1 also.
> I am not entirely sure the way the :regexp to abbrev table should be
> provided is well thought-out. See my question to emacs-devel:
> http://permalink.gmane.org/gmane.emacs.devel/123749.
>
> Cheers,
>
> Leo
>
>
>
>
--
Thierry Volpiatto
Gpg key: http://pgp.mit.edu/
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Negate a regexp
2010-04-19 17:54 ` Thierry Volpiatto
@ 2010-04-19 18:35 ` Leo
2010-04-19 21:41 ` Thierry Volpiatto
0 siblings, 1 reply; 7+ messages in thread
From: Leo @ 2010-04-19 18:35 UTC (permalink / raw)
To: help-gnu-emacs
On 2010-04-19 18:54 +0100, Thierry Volpiatto wrote:
> It will return \\coor because \ have to be escaped.
>
> (save-excursion (when (looking-back "^\\(\\\\[a-z]*\\)") (match-string 0)))
>
> It match on 1 also.
This is a special case for the special example in my previous post.
What about co\or ? It is still text contains word or symbol or \ (i.e.
\sw \s_ or \s\).
Leo
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Negate a regexp
2010-04-19 18:35 ` Leo
@ 2010-04-19 21:41 ` Thierry Volpiatto
2010-04-20 13:44 ` Leo
0 siblings, 1 reply; 7+ messages in thread
From: Thierry Volpiatto @ 2010-04-19 21:41 UTC (permalink / raw)
To: help-gnu-emacs
Leo <sdl.web@gmail.com> writes:
> On 2010-04-19 18:54 +0100, Thierry Volpiatto wrote:
>> It will return \\coor because \ have to be escaped.
>>
>> (save-excursion (when (looking-back "^\\(\\\\[a-z]*\\)") (match-string 0)))
>>
>> It match on 1 also.
>
> This is a special case for the special example in my previous post.
>
> What about co\or ? It is still text contains word or symbol or \ (i.e.
> \sw \s_ or \s\).
Try to use the greedy arg:
try matching
\co\o_r-!-
(when (looking-back "\\([\\\\a-z_]*\\)" nil 'greedy)
(match-string-no-properties 0))
==>
"\\co\\o_r"
--
Thierry Volpiatto
Gpg key: http://pgp.mit.edu/
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2010-04-20 13:44 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-04-19 14:57 Negate a regexp Leo
2010-04-19 15:51 ` Drew Adams
2010-04-19 17:32 ` Leo
2010-04-19 17:54 ` Thierry Volpiatto
2010-04-19 18:35 ` Leo
2010-04-19 21:41 ` Thierry Volpiatto
2010-04-20 13:44 ` Leo
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).