* RegExp question
@ 2004-09-23 16:41 Ryan Bowman
2004-09-23 18:05 ` Greg Hill
0 siblings, 1 reply; 13+ messages in thread
From: Ryan Bowman @ 2004-09-23 16:41 UTC (permalink / raw)
I have a regexp "repeat\\(-[xy]?\\)?" this should
match
repeat
repeat-x
repeat-y
, which it does, however it also matches
background-repeat:
which I don't want it to.
So I changed it to this "repeat\\(-[xy]?\\)?[^:]"
so it won't match background-repeat: but then it no
longer matches repeat,
I assume because [^:] actually means to match
something, but not a ':'
so how do I specifiy that I don't care if anything
follows the patter or not,
so long as it is NOT ':'?
=====
---
Ryan
The door at the end of the tunnel is far too small...
- Closing In 2.0 - Don't Be Afraid - Information Society - insoc.org
---
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: RegExp question
2004-09-23 16:41 RegExp question Ryan Bowman
@ 2004-09-23 18:05 ` Greg Hill
0 siblings, 0 replies; 13+ messages in thread
From: Greg Hill @ 2004-09-23 18:05 UTC (permalink / raw)
[-- Attachment #1.1: Type: text/plain, Size: 1079 bytes --]
Ryan,
Depending on exactly what you are trying to accomplish, this may or
may not do the trick for you. For example, if the word "repeat" is
followed by a space character, the space character _will_ be part of
the match. But if the word you are searching for is always at the
end of a line, this should do what you want.
(re-search-forward "repeat\\(-[xy]?\\)?\\([^:\n]+\\|$\\)")
If your requirements are more complicated, it may be necessary to
write your own function that does more than just a single call to
re-search-forward.
--Greg
At 9:41 AM -0700 9/23/04, Ryan Bowman wrote:
>I have a regexp "repeat\\(-[xy]?\\)?" this should
>match
>repeat
>repeat-x
>repeat-y
>, which it does, however it also matches
>background-repeat:
>which I don't want it to.
>So I changed it to this "repeat\\(-[xy]?\\)?[^:]"
>so it won't match background-repeat: but then it no
>longer matches repeat,
>I assume because [^:] actually means to match
>something, but not a ':'
>so how do I specifiy that I don't care if anything
>follows the patter or not,
>so long as it is NOT ':'?
[-- Attachment #1.2: Type: text/html, Size: 1767 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] 13+ messages in thread
[parent not found: <mailman.3776.1095958718.1998.help-gnu-emacs@gnu.org>]
* RE: RegExp question
@ 2004-09-23 20:23 JayBingham
2004-09-24 19:43 ` Ryan Bowman
0 siblings, 1 reply; 13+ messages in thread
From: JayBingham @ 2004-09-23 20:23 UTC (permalink / raw)
On Thursday, September 23, 2004 11:42 AM Ryan Bowman wrote:
> So I changed it to this "repeat\\(-[xy]?\\)?[^:]"
> so it won't match background-repeat: but then it no
> longer matches repeat,
> I assume because [^:] actually means to match
> something, but not a ':'
> so how do I specifiy that I don't care if anything
> follows the patter or not,
> so long as it is NOT ':'?
I am curious which version of emacs you are running. I have emacs
21.2 loaded on my Windows 2k system and the above regexp matches
every repeat in your message except those followed by a ":" and one
that I added at the end of the buffer which does not have anything
following it. You are correct in your assumption that [^:] actually
means to match something. Remember that a new line is something, as
opposed to nothing. This means that when repeat occurs at the end of
a line the new line is included in the matched string and point will
follow it (be at the start of the next line) so it may appear that it
was not matched.
<Do not reply to the above address, reply only to the list>
-_
J_)
C_)ingham
. Hewlett-Packard
. Austin, TX
. Language is the apparel in which your thoughts parade in public.
. Never clothe them in vulgar and shoddy attire. -Dr. George W.
Crane-
^ permalink raw reply [flat|nested] 13+ messages in thread
* RE: RegExp question
2004-09-23 20:23 JayBingham
@ 2004-09-24 19:43 ` Ryan Bowman
0 siblings, 0 replies; 13+ messages in thread
From: Ryan Bowman @ 2004-09-24 19:43 UTC (permalink / raw)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=us-ascii, Size: 1869 bytes --]
--- JayBingham <binghamjc@bluebottle.com> wrote:
> On Thursday, September 23, 2004 11:42 AM Ryan Bowman
> wrote:
>
> > So I changed it to this "repeat\\(-[xy]?\\)?[^:]"
> > so it won't match background-repeat: but then it
> no
> > longer matches repeat,
> > I assume because [^:] actually means to match
> > something, but not a ':'
> > so how do I specifiy that I don't care if anything
> > follows the patter or not,
> > so long as it is NOT ':'?
>
> I am curious which version of emacs you are running.
> I have emacs
> 21.2 loaded on my Windows 2k system and the above
> regexp matches
> every repeat in your message except those followed
> by a ":" and one
> that I added at the end of the buffer which does not
> have anything
> following it. You are correct in your assumption
> that [^:] actually
> means to match something. Remember that a new line
> is something, as
> opposed to nothing. This means that when repeat
> occurs at the end of
> a line the new line is included in the matched
> string and point will
> follow it (be at the start of the next line) so it
> may appear that it
> was not matched.
>
> <Do not reply to the above address, reply only to
> the list>
>
> -_
> J_)
> C_)ingham
> . Hewlett-Packard
> . Austin, TX
> . Language is the apparel in which your thoughts
> parade in public.
> . Never clothe them in vulgar and shoddy attire.
> -Dr. George W.
> Crane-
>
>
>
> _______________________________________________
> Help-gnu-emacs mailing list
> Help-gnu-emacs@gnu.org
> http://lists.gnu.org/mailman/listinfo/help-gnu-emacs
>
=====
---
Ryan
The door at the end of the tunnel is far too small...
- Closing In 2.0 - Don't Be Afraid - Information Society - insoc.org
---
__________________________________
Do you Yahoo!?
Y! Messenger - Communicate in real time. Download now.
http://messenger.yahoo.com
^ permalink raw reply [flat|nested] 13+ messages in thread
[parent not found: <20040924194238.40080.qmail@web51606.mail.yahoo.com>]
* RE: RegExp question
[not found] <20040924194238.40080.qmail@web51606.mail.yahoo.com>
@ 2004-09-28 18:21 ` JayBingham
0 siblings, 0 replies; 13+ messages in thread
From: JayBingham @ 2004-09-28 18:21 UTC (permalink / raw)
<DO NOT reply to the address this was sent from, reply only to the
list>
Quoting Ryan Bowman <rlb_emacs@yahoo.com>:
> Except I'm adding it to font-lock-keyword so it will
> change the font face on a match, repeat followed by a
> newline is not matched by the above expression, though
> it should be. I'm running 21.3.50.1 on WinXP (from
> nqmacs.sourceforge.net).
>
Well that may explain why it works for me (using 21.2). It seems
that
something changed between 21.2 and 21.3. Maybe it is a bug.
A word of advice here, it is always proper to include the version and
environment that you are using when asking a question about something
that does not seem to be working the way you expect it to work.
-_
J_)
C_)ingham
. Hewlett-Packard
. Austin, TX
. Language is the apparel in which your thoughts parade in public.
. Never clothe them in vulgar and shoddy attire. -Dr. George W.
Crane-
^ permalink raw reply [flat|nested] 13+ messages in thread
* AW: replace a textblock in multiple files
@ 2006-09-26 11:18 C.Strobl
2006-09-26 12:09 ` regexp question C.Strobl
[not found] ` <mailman.7422.1159272599.9609.help-gnu-emacs@gnu.org>
0 siblings, 2 replies; 13+ messages in thread
From: C.Strobl @ 2006-09-26 11:18 UTC (permalink / raw)
thanks, but maybe my question was too short.
1) i want to work on several subdirectories, not only in one directory
2) i want to replace blocks consisting of more than one line.
is that possible at all
tanks again
christian
p.s. i know it's always possible with programming elisp. but i want to know if it's possible with simple emacs commands?
> -----Ursprüngliche Nachricht-----
> Von: help-gnu-emacs-bounces+c.strobl=dlr.de@gnu.org
> [mailto:help-gnu-emacs-bounces+c.strobl=dlr.de@gnu.org] Im
> Auftrag von Benjamin Rutt
> Gesendet: Dienstag, 26. September 2006 02:52
> An: help-gnu-emacs@gnu.org
> Betreff: Re: replace a textblock in multiple files
>
> <C.Strobl@dlr.de> writes:
>
> > hello all,
> > only a short and simple question: whats the best way to replace a
> > textblock in multiple files.
> > thanks and i hope the question is not to easy christian
>
> M-x dired
>
> mark desired files with 'm'
>
> Q
> --
> Benjamin Rutt
> _______________________________________________
> help-gnu-emacs mailing list
> help-gnu-emacs@gnu.org
> http://lists.gnu.org/mailman/listinfo/help-gnu-emacs
>
^ permalink raw reply [flat|nested] 13+ messages in thread
* regexp question
2006-09-26 11:18 AW: replace a textblock in multiple files C.Strobl
@ 2006-09-26 12:09 ` C.Strobl
2006-09-26 17:16 ` Peter Dyballa
[not found] ` <mailman.7422.1159272599.9609.help-gnu-emacs@gnu.org>
1 sibling, 1 reply; 13+ messages in thread
From: C.Strobl @ 2006-09-26 12:09 UTC (permalink / raw)
hello all,
i want to replace a block beginning with <column_right> and ending with
</column_right>, with a variable number of lines between with another
text block. is that possible with regular expressions and if yes, how?
i don't know how to find an optional number of complete lines.
how can i find this text block with a regular expression?
<column_right>
<!-- background attribute options: black, white, grey,
blue, red, green, orange -->
<feature_block background="orange">
<feature_text></feature_text>
<feature_image
height="1">spacer_grey.gif</feature_image>
<feature_text></feature_text>
<feature_image
type="intern">projects/gitews/logo_175.gif</feature_image>
<feature_text></feature_text>
<feature_image
height="1">spacer_grey.gif</feature_image>
<feature_text></feature_text>
<feature_text>Work Package 4100</feature_text>
<feature_text>provided by XYZ</feature_text>
<feature_text></feature_text>
<feature_image
height="5">spacer_grey.gif</feature_image>
<feature_text></feature_text>
<feature_header>Contact:</feature_header>
<feature_text></feature_text>
<feature_text></feature_text>
</feature_block>
</column_right>
christian
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: regexp question
2006-09-26 12:09 ` regexp question C.Strobl
@ 2006-09-26 17:16 ` Peter Dyballa
2006-09-29 22:03 ` Dieter Wilhelm
0 siblings, 1 reply; 13+ messages in thread
From: Peter Dyballa @ 2006-09-26 17:16 UTC (permalink / raw)
Cc: help-gnu-emacs, rutt.4
Am 26.09.2006 um 14:09 schrieb <C.Strobl@dlr.de>:
> how can i find this text block with a regular expression?
<column_right>[-_ !",./0-9:<=>A-Za-z
]*</column_right>
- has to come first, _ is just close, then come SPACE and TAB, ...,
and finally a newline, C-q C-j.
To determine the characters in the region do this shell-command-on-
region:
sed -e 's/\(.\)/\1·/g' | tr '·' '\012' | sort -u
--
Greetings
Pete
"I wouldn't recommend sex, drugs or insanity for everyone, but
they've always worked for me."
-- Hunter S. Thompson
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: regexp question
2006-09-26 17:16 ` Peter Dyballa
@ 2006-09-29 22:03 ` Dieter Wilhelm
2006-09-30 8:53 ` Peter Dyballa
0 siblings, 1 reply; 13+ messages in thread
From: Dieter Wilhelm @ 2006-09-29 22:03 UTC (permalink / raw)
Cc: C.Strobl, help-gnu-emacs, rutt.4
Peter Dyballa <Peter_Dyballa@Web.DE> writes:
> Am 26.09.2006 um 14:09 schrieb <C.Strobl@dlr.de>:
>
>> how can i find this text block with a regular expression?
>
> <column_right>[-_ !",./0-9:<=>A-Za-z
> ]*</column_right>
>
> - has to come first, _ is just close, then come SPACE and TAB, ...,
> and finally a newline, C-q C-j.
>
> To determine the characters in the region do this shell-command-on-
> region:
>
> sed -e 's/\(.\)/\1·/g' | tr '·' '\012' | sort -u
^
I assume above construct is necessary for (older) UNIX systems? I
tried:
sed -e 's/\(.\)/\1\n/g | sort -u
which is working on my Gnu/Linux system.
--
Best wishes
H. Dieter Wilhelm
Darmstadt, Germany
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: regexp question
2006-09-29 22:03 ` Dieter Wilhelm
@ 2006-09-30 8:53 ` Peter Dyballa
0 siblings, 0 replies; 13+ messages in thread
From: Peter Dyballa @ 2006-09-30 8:53 UTC (permalink / raw)
Cc: C.Strobl, help-gnu-emacs, rutt.4
Am 30.09.2006 um 00:03 schrieb Dieter Wilhelm:
> sed -e 's/\(.\)/\1\n/g | sort -u
>
> which is working on my Gnu/Linux system.
Your shell is faulty. A quoted sequence has to start and to end.
\n does not seem to work for me ...
Anyway, Florian Kaufmann's \(.\|^J\)*? is the optimal expression: it
does not need a contents analysis.
--
Mit friedvollen Grüßen
Pete (:
_ / __ - -
_/ \__/_/ - -
(´`) (´`) - -
`´ `´
^ permalink raw reply [flat|nested] 13+ messages in thread
[parent not found: <mailman.7422.1159272599.9609.help-gnu-emacs@gnu.org>]
* Re: regexp question
[not found] ` <mailman.7422.1159272599.9609.help-gnu-emacs@gnu.org>
@ 2006-09-27 7:58 ` Florian Kaufmann
0 siblings, 0 replies; 13+ messages in thread
From: Florian Kaufmann @ 2006-09-27 7:58 UTC (permalink / raw)
> i want to replace a block beginning with <column_right> and ending with
> </column_right>, with a variable number of lines between with another
> text block. ext block with a regular expression?
I would use:
<column_right>\(.\|^J\)*?</column_right>
Where the ^J results from pressing C-q C-j.
The details: Since the dot . does much any character but the newline, I
use the construct \(.\|^J\) which now matches really any character. *?
is the lazy version of the greedy *. Meaning that as few as possible
are selected. This prevents from selecting too much. Only * instead of
*? would much both of the following lines instead of only one.
<column_right>line1</column_right>
<column_right>line2</column_right>
However, my regex fails to match nested tags. In the following example
<column_right><column_right></column_right></column_right>
the match is
<column_right><column_right></column_right>
which is not what you want. I don't know how to make a regular
expression which would also support this case. I'm sure you would find
the answer in the book "Mastering regular expressions"
Flo
^ permalink raw reply [flat|nested] 13+ messages in thread
* regexp question
@ 2011-01-06 16:14 Thorsten Bonow
2011-01-07 10:05 ` tomas
0 siblings, 1 reply; 13+ messages in thread
From: Thorsten Bonow @ 2011-01-06 16:14 UTC (permalink / raw)
To: help-gnu-emacs
Hi,
I wrote the following defun:
(defun yyy-rmligs()
"Function to call `query-replace-regexp' and search
for words, ignoring LaTeX commands starting with a backslash,
which contain ligatures 'ff', 'fi', 'fl', 'ffi' and 'ffl' and
queries about replacing them with their LaTeX non-ligature
variant. E.g. 'shelfful' could be replaced by 'shelf\"|ful',
while '\\flushright' is ignored."
(interactive)
(query-replace-regexp
"\\([^\\\\]\\b\\w*\\)f\\(f\\|i\\|l\\|fi\\|fl\\)\\(\\w*\\b\\)"
"\\1f\"|\\2\\3)"))
It works, unless there is more then one ligature in the word.
I can replace 'aaaflaaa' with 'aaaf"|laaa', but the defun fails to replace the
first occurrences of 'fl' in 'aaaflaaaflaaa'.
Help on the rexeps involved would be appreciated. Thx!
Toto
PS: Yes I know of the rmligs program; my need is for other languages than
German.
I know that for LaTeX documents I should (and will) use
`reftex-query-replace-document' instead of `query-replace-regexp'.
Do words in the English language exist which have more than one ligature?
--
"A Korean newspaper wrote that Aachen University is the MIT of Europe."
Burkhard Rauhut / "Anything that's the something of something isn't
really the anything of anything." Lisa Simpson
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: regexp question
2011-01-06 16:14 Thorsten Bonow
@ 2011-01-07 10:05 ` tomas
0 siblings, 0 replies; 13+ messages in thread
From: tomas @ 2011-01-07 10:05 UTC (permalink / raw)
To: Thorsten Bonow; +Cc: help-gnu-emacs
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Thu, Jan 06, 2011 at 05:14:59PM +0100, Thorsten Bonow wrote:
>
> Hi,
>
> I wrote the following defun:
>
> (defun yyy-rmligs()
> "Function to call `query-replace-regexp' and search
> for words, ignoring LaTeX commands starting with a backslash,
> which contain ligatures 'ff', 'fi', 'fl', 'ffi' and 'ffl' and
> queries about replacing them with their LaTeX non-ligature
> variant. E.g. 'shelfful' could be replaced by 'shelf\"|ful',
> while '\\flushright' is ignored."
>
> (interactive)
> (query-replace-regexp
> "\\([^\\\\]\\b\\w*\\)f\\(f\\|i\\|l\\|fi\\|fl\\)\\(\\w*\\b\\)"
> "\\1f\"|\\2\\3)"))
>
> It works, unless there is more then one ligature in the word.
Hm. Tough one. You might substitute the \w* by its non-greedy \w*?. But
then I guess you would just hit the *first* ligature and pass the
second. Possibly you'd have to modify the "head", to allow it to begin
with \w right away when not at word boundaries (i.e. in the middle of
the word).
Or you bite the bullet and code the loop yourself, so you have more
control of the restart points.
Regards
- -- tomás
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
iD8DBQFNJuWDBcgs9XrR2kYRAiFgAJ4+PG0PZZEV3Umom98OfiiH3bWvMgCcDvQ9
BEeovKmIIWdO8XdmHgtZ7W4=
=RFxZ
-----END PGP SIGNATURE-----
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2011-01-07 10:05 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-09-23 16:41 RegExp question Ryan Bowman
2004-09-23 18:05 ` Greg Hill
[not found] <mailman.3776.1095958718.1998.help-gnu-emacs@gnu.org>
2004-09-23 18:09 ` Stefan Monnier
-- strict thread matches above, loose matches on Subject: below --
2004-09-23 20:23 JayBingham
2004-09-24 19:43 ` Ryan Bowman
[not found] <20040924194238.40080.qmail@web51606.mail.yahoo.com>
2004-09-28 18:21 ` JayBingham
2006-09-26 11:18 AW: replace a textblock in multiple files C.Strobl
2006-09-26 12:09 ` regexp question C.Strobl
2006-09-26 17:16 ` Peter Dyballa
2006-09-29 22:03 ` Dieter Wilhelm
2006-09-30 8:53 ` Peter Dyballa
[not found] ` <mailman.7422.1159272599.9609.help-gnu-emacs@gnu.org>
2006-09-27 7:58 ` Florian Kaufmann
2011-01-06 16:14 Thorsten Bonow
2011-01-07 10:05 ` tomas
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).