* RegExp: match everything except a certain string
@ 2007-11-20 16:08 Sven Bretfeld
2007-11-20 17:50 ` Andreas Röhler
[not found] ` <mailman.3839.1195580948.18990.help-gnu-emacs@gnu.org>
0 siblings, 2 replies; 8+ messages in thread
From: Sven Bretfeld @ 2007-11-20 16:08 UTC (permalink / raw)
To: help-gnu-emacs
[-- Attachment #1.1: Type: text/plain, Size: 694 bytes --]
Hello to all
A RegExp beginner's question again. I cannot find a way to search for
a regexp that matches everything except of one certain string. The
problem is:
author = {somename},
editor = {},
title = {sometitle},
subtitle = {},
series = {},
url = {}
I want to find a regexp that matches every line with empty {} except
of the "subtitle line". I've come that far:
^ \<[^s].* = {},*
But this one also excludes the "series line", of course. I was
thinking of \<[^s][^u] but this doesn't work, since, then, the initial
s of "subtitle" is matched again.
What is the syntax for find .* except of the string "subtitle"? I
didn't recognize this in the Lisp info.
Thanks for help
Sven
[-- Attachment #1.2: Type: application/pgp-signature, Size: 188 bytes --]
[-- Attachment #2: Type: text/plain, Size: 152 bytes --]
_______________________________________________
help-gnu-emacs mailing list
help-gnu-emacs@gnu.org
http://lists.gnu.org/mailman/listinfo/help-gnu-emacs
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: RegExp: match everything except a certain string
2007-11-20 16:08 RegExp: match everything except a certain string Sven Bretfeld
@ 2007-11-20 17:50 ` Andreas Röhler
2007-11-20 20:36 ` Sven Bretfeld
[not found] ` <mailman.3846.1195590989.18990.help-gnu-emacs@gnu.org>
[not found] ` <mailman.3839.1195580948.18990.help-gnu-emacs@gnu.org>
1 sibling, 2 replies; 8+ messages in thread
From: Andreas Röhler @ 2007-11-20 17:50 UTC (permalink / raw)
To: help-gnu-emacs
Am Dienstag, 20. November 2007 17:08 schrieb Sven Bretfeld:
> Hello to all
>
> A RegExp beginner's question again. I cannot find a way to search for
> a regexp that matches everything except of one certain string. The
> problem is:
>
> author = {somename},
> editor = {},
> title = {sometitle},
> subtitle = {},
> series = {},
> url = {}
>
> I want to find a regexp that matches every line with empty {} except
> of the "subtitle line". I've come that far:
>
> ^ \<[^s].* = {},*
>
> But this one also excludes the "series line", of course. I was
> thinking of \<[^s][^u] but this doesn't work, since, then, the initial
> s of "subtitle" is matched again.
>
> What is the syntax for find .* except of the string "subtitle"? I
> didn't recognize this in the Lisp info.
>
> Thanks for help
>
> Sven
Got it with:
[^s]?[^u]?[^b]?[^t]?[^i]?[^t]?[^l]?[^e] = {},?$
Please don't ask why :)
Anyway--you will know that and it's not the precise
answer-- it might be useful to point at
M-x shell-command-on-region
grep {} | sed /subtitle/d
as an easy-to-use solution.
Andreas Röhler
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: RegExp: match everything except a certain string
2007-11-20 17:50 ` Andreas Röhler
@ 2007-11-20 20:36 ` Sven Bretfeld
2007-11-20 21:05 ` Lennart Borgman (gmail)
[not found] ` <mailman.3846.1195590989.18990.help-gnu-emacs@gnu.org>
1 sibling, 1 reply; 8+ messages in thread
From: Sven Bretfeld @ 2007-11-20 20:36 UTC (permalink / raw)
To: help-gnu-emacs
[-- Attachment #1.1: Type: text/plain, Size: 852 bytes --]
Hello Andreas
Andreas Röhler <andreas.roehler@online.de> writes:
>> author = {somename},
>> editor = {},
>> title = {sometitle},
>> subtitle = {},
>> series = {},
>> url = {}
>>
>> I want to find a regexp that matches every line with empty {} except
>> of the "subtitle line". I've come that far:
>>
> Got it with:
>
> [^s]?[^u]?[^b]?[^t]?[^i]?[^t]?[^l]?[^e] = {},?$
>
> Please don't ask why :)
That's working. Thanks. (I don't ask.)
> Anyway--you will know that and it's not the precise
> answer-- it might be useful to point at
>
> M-x shell-command-on-region
>
> grep {} | sed /subtitle/d
>
> as an easy-to-use solution.
It's a good idea to use a sed pipe. But it doesn't matter how much
there is to type, since I need the expression for a function. So I
only have to type it once.
Greetings
Sven
[-- Attachment #1.2: Type: application/pgp-signature, Size: 188 bytes --]
[-- Attachment #2: Type: text/plain, Size: 152 bytes --]
_______________________________________________
help-gnu-emacs mailing list
help-gnu-emacs@gnu.org
http://lists.gnu.org/mailman/listinfo/help-gnu-emacs
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: RegExp: match everything except a certain string
2007-11-20 20:36 ` Sven Bretfeld
@ 2007-11-20 21:05 ` Lennart Borgman (gmail)
2007-11-20 21:31 ` Sven Bretfeld
0 siblings, 1 reply; 8+ messages in thread
From: Lennart Borgman (gmail) @ 2007-11-20 21:05 UTC (permalink / raw)
To: Sven Bretfeld; +Cc: help-gnu-emacs
Sven Bretfeld wrote:
> Hello Andreas
>
> Andreas Röhler <andreas.roehler@online.de> writes:
>
>>> author = {somename},
>>> editor = {},
>>> title = {sometitle},
>>> subtitle = {},
>>> series = {},
>>> url = {}
>>>
>>> I want to find a regexp that matches every line with empty {} except
>>> of the "subtitle line". I've come that far:
>>>
>> Got it with:
>>
>> [^s]?[^u]?[^b]?[^t]?[^i]?[^t]?[^l]?[^e] = {},?$
>>
>> Please don't ask why :)
>
> That's working. Thanks. (I don't ask.)
>
>> Anyway--you will know that and it's not the precise
>> answer-- it might be useful to point at
>>
>> M-x shell-command-on-region
>>
>> grep {} | sed /subtitle/d
>>
>> as an easy-to-use solution.
>
> It's a good idea to use a sed pipe. But it doesn't matter how much
> there is to type, since I need the expression for a function. So I
> only have to type it once.
Then it is probably much easier to use two step aproach:
1) use a simpler regexp
2) test if "subtitle" was in the match
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: RegExp: match everything except a certain string
2007-11-20 21:05 ` Lennart Borgman (gmail)
@ 2007-11-20 21:31 ` Sven Bretfeld
0 siblings, 0 replies; 8+ messages in thread
From: Sven Bretfeld @ 2007-11-20 21:31 UTC (permalink / raw)
To: help-gnu-emacs
[-- Attachment #1.1: Type: text/plain, Size: 470 bytes --]
Hi Lennart
"Lennart Borgman (gmail)" <lennart.borgman@gmail.com> writes:
>> It's a good idea to use a sed pipe. But it doesn't matter how much
>> there is to type, since I need the expression for a function. So I
>> only have to type it once.
>
> Then it is probably much easier to use two step aproach:
>
> 1) use a simpler regexp
> 2) test if "subtitle" was in the match
This is going to be my first function ever. I will try if I can do it
that way.
Thanks
Sven
[-- Attachment #1.2: Type: application/pgp-signature, Size: 188 bytes --]
[-- Attachment #2: Type: text/plain, Size: 152 bytes --]
_______________________________________________
help-gnu-emacs mailing list
help-gnu-emacs@gnu.org
http://lists.gnu.org/mailman/listinfo/help-gnu-emacs
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: RegExp: match everything except a certain string
[not found] ` <mailman.3846.1195590989.18990.help-gnu-emacs@gnu.org>
@ 2007-11-28 16:19 ` Sven Utcke
2007-11-28 21:22 ` Malte Spiess
0 siblings, 1 reply; 8+ messages in thread
From: Sven Utcke @ 2007-11-28 16:19 UTC (permalink / raw)
To: help-gnu-emacs
Sven Bretfeld <sven.bretfeld@gmx.ch> writes:
> Hello Andreas
>
> Andreas Röhler <andreas.roehler@online.de> writes:
>
> >> author = {somename},
> >> editor = {},
> >> title = {sometitle},
> >> subtitle = {},
> >> series = {},
> >> url = {}
> >>
> >> I want to find a regexp that matches every line with empty {} except
> >> of the "subtitle line". I've come that far:
> >>
> > Got it with:
> >
> > [^s]?[^u]?[^b]?[^t]?[^i]?[^t]?[^l]?[^e] = {},?$
> >
> > Please don't ask why :)
>
> That's working. Thanks. (I don't ask.)
I haven't followed the original thread, so I might be way of the mark
here, but the above would of course not find "title = {}" either (as
well as quite a few less likely variations).
If using external programs is an option,
grep '\{\}' | grep -v subtitle
would do what you are looking for...
Sven
--
___ _ _____ ___ Dr.-Ing. Sven Utcke ___ ___ _____ __
/ __| |/ / __| __| phone: +49 40 8998-5317 | \| __/ __\ \ / /
| (_ | ' <\__ \__ \ fax : +49 40 8994-5317 (NEW) | |) | _|\__ \\ V /
\___|_|\_\___|___/ http://www.desy.de/~utcke (to come)|___/|___|___/ |_|
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: RegExp: match everything except a certain string
2007-11-28 16:19 ` Sven Utcke
@ 2007-11-28 21:22 ` Malte Spiess
0 siblings, 0 replies; 8+ messages in thread
From: Malte Spiess @ 2007-11-28 21:22 UTC (permalink / raw)
To: help-gnu-emacs
Sven Utcke <utcke+news@informatik.uni-hamburg.de> writes:
> Sven Bretfeld <sven.bretfeld@gmx.ch> writes:
>
>> Hello Andreas
>>
>> Andreas Röhler <andreas.roehler@online.de> writes:
>>
>> >> author = {somename},
>> >> editor = {},
>> >> title = {sometitle},
>> >> subtitle = {},
>> >> series = {},
>> >> url = {}
>> >>
>> >> I want to find a regexp that matches every line with empty {} except
>> >> of the "subtitle line". I've come that far:
>> >>
>> > Got it with:
>> >
>> > [^s]?[^u]?[^b]?[^t]?[^i]?[^t]?[^l]?[^e] = {},?$
>> >
>> > Please don't ask why :)
>>
>> That's working. Thanks. (I don't ask.)
>
> I haven't followed the original thread, so I might be way of the mark
> here, but the above would of course not find "title = {}" either (as
> well as quite a few less likely variations).
Yeah, you are right, the [^s]? (and so on) seem pretty useless because
the empty string matches them. The whole expression can be reduced to
[^e] = {},?$
which means that any string that does not end with an "e" should be
matched... (it does that here)
Greetings
Malte
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: RegExp: match everything except a certain string
[not found] ` <mailman.3839.1195580948.18990.help-gnu-emacs@gnu.org>
@ 2007-11-30 16:26 ` Stefan Monnier
0 siblings, 0 replies; 8+ messages in thread
From: Stefan Monnier @ 2007-11-30 16:26 UTC (permalink / raw)
To: help-gnu-emacs
> [^s]?[^u]?[^b]?[^t]?[^i]?[^t]?[^l]?[^e] = {},?$
Nice try, but no cigar ;-)
How 'bout something like:
"\\(?:[^s]\\|s\\(?:[^u]\\|u\\(?:[^b]\\|b\\(?:[^t]\\|t\\(?:[^i]\\|i\\(?:[^t]\\|t\\(?:[^l]\\|l\\(?:[^e]\\|e[^\t\n ]\\)\\)\\)\\)\\)\\)\\)\\)"
this is just a starting point, because even if you have "subtitle" in
your buffer the "title" part doesn't match "subtitle", so
a regexp-search may find "title" as a match: negation in regexp search
is pretty tricky.
Stefan
(defun regexp-not-in (words endchars &optional prefix)
"Return a regexp that matches anything other than words in WORDS.
ENDCHARS is a list containing the chars that can appear after a word."
;; `prefix' is only used internally.
(if prefix (setq words (all-completions prefix words)) (setq prefix ""))
(let* ((pos (length prefix))
(empty (when (member prefix words)
(setq words (remove prefix words)) t))
(chars (delete-dups (mapcar (lambda (word) (aref word pos)) words)))
(chars-re (regexp-opt-charset (if empty (nconc chars endchars) chars)))
(nonchars-re (concat "[^" (substring chars-re 1 -1) "]")))
(cond
((and empty (null endchars))
;; If there are no termination chars, then we have to simply disallow
;; this match altogether.
"\\`")
((null chars) nonchars-re)
(t
(concat "\\(?:" nonchars-re
"\\|"
(mapconcat (lambda (char)
(setq char (string char))
(concat char
(regexp-not-in words endchars
(concat prefix char))))
chars
"\\|")
"\\)")))))
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2007-11-30 16:26 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-11-20 16:08 RegExp: match everything except a certain string Sven Bretfeld
2007-11-20 17:50 ` Andreas Röhler
2007-11-20 20:36 ` Sven Bretfeld
2007-11-20 21:05 ` Lennart Borgman (gmail)
2007-11-20 21:31 ` Sven Bretfeld
[not found] ` <mailman.3846.1195590989.18990.help-gnu-emacs@gnu.org>
2007-11-28 16:19 ` Sven Utcke
2007-11-28 21:22 ` Malte Spiess
[not found] ` <mailman.3839.1195580948.18990.help-gnu-emacs@gnu.org>
2007-11-30 16:26 ` 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).