unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* multiple alternatives regexp question
       [not found] <E1Ae1Fl-0004fM-Lz@monty-python.gnu.org>
@ 2004-01-07  1:19 ` Joe Corneli
       [not found] ` <mailman.87.1073442133.928.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 4+ messages in thread
From: Joe Corneli @ 2004-01-07  1:19 UTC (permalink / raw)


I am interested in a regexp that I think should be written
like this (for inclusion in a program):

"\\([[:lower:]]\\|[[:digit:]]\\|A\\)\\([A-Z]\\)"

In other words, a lower case letter, or a digit, or an `A',
followed by a capital letter.

Unfortunately, when I search and replace like so:

(let ((case-fold-search nil))
(while (re-search-forward "\\([[:lower:]]\\|[[:digit:]]\\|A\\)\\([A-Z]\\)"
                          nil t)
  (replace-match (concat (match-string 1) " " (match-string 2)))))

on something
like 

ProofOfPropertiesOfTraceOfAMatrix 

I get back

Proof Of Properties Of Trace Of AMatrix 
                                 ^

(Note that if you run the above code on the output string, it will
make a space in the appropriate place!)

Why is the `A' not being treated the way I want the first time
around?

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

* Re: multiple alternatives regexp question
       [not found] ` <mailman.87.1073442133.928.help-gnu-emacs@gnu.org>
@ 2004-01-07  2:14   ` Jesper Harder
  2004-01-07 10:13   ` Stefan Monnier
  1 sibling, 0 replies; 4+ messages in thread
From: Jesper Harder @ 2004-01-07  2:14 UTC (permalink / raw)


Joe Corneli <jcorneli@math.utexas.edu> writes:

> Unfortunately, when I search and replace like so:
>
> (let ((case-fold-search nil))
> (while (re-search-forward "\\([[:lower:]]\\|[[:digit:]]\\|A\\)\\([A-Z]\\)"
>                           nil t)
>   (replace-match (concat (match-string 1) " " (match-string 2)))))
>
> on something like
>
> ProofOfPropertiesOfTraceOfAMatrix 
>
> I get back
>
> Proof Of Properties Of Trace Of AMatrix 
>                                  ^
> Why is the `A' not being treated the way I want the first time
> around?

It doesn't work because `replace-match' leaves point after the
replacement text.  You could use something like this instead:

   (replace-match "\\1 " t nil nil 1)

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

* Re: multiple alternatives regexp question
       [not found] ` <mailman.87.1073442133.928.help-gnu-emacs@gnu.org>
  2004-01-07  2:14   ` Jesper Harder
@ 2004-01-07 10:13   ` Stefan Monnier
  1 sibling, 0 replies; 4+ messages in thread
From: Stefan Monnier @ 2004-01-07 10:13 UTC (permalink / raw)


> I am interested in a regexp that I think should be written
> like this (for inclusion in a program):

> "\\([[:lower:]]\\|[[:digit:]]\\|A\\)\\([A-Z]\\)"

You mean "\\([[:lower:][:digit:]A]\\)\\([[:upper:]]\\)" ?

> Why is the `A' not being treated the way I want the first time
> around?

See Jesper's answer,


        Stefan

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

* Re: multiple alternatives regexp question
       [not found] <E1AeGBR-00015s-IU@monty-python.gnu.org>
@ 2004-01-07 16:57 ` Joe Corneli
  0 siblings, 0 replies; 4+ messages in thread
From: Joe Corneli @ 2004-01-07 16:57 UTC (permalink / raw)


> You mean "\\([[:lower:][:digit:]A]\\)\\([[:upper:]]\\)" ?

I suppose that's equivalent to what I wrote, though I didn't
know could do that...

Anyway, I see why the replacement doesn't work the first
time & consequently why it does work the second time, so
thanks for the help!

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

end of thread, other threads:[~2004-01-07 16:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <E1Ae1Fl-0004fM-Lz@monty-python.gnu.org>
2004-01-07  1:19 ` multiple alternatives regexp question Joe Corneli
     [not found] ` <mailman.87.1073442133.928.help-gnu-emacs@gnu.org>
2004-01-07  2:14   ` Jesper Harder
2004-01-07 10:13   ` Stefan Monnier
     [not found] <E1AeGBR-00015s-IU@monty-python.gnu.org>
2004-01-07 16:57 ` Joe Corneli

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).