* What is wrong with this regexp search?
@ 2006-11-10 16:24 Mirko
2006-11-10 16:46 ` rgb
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Mirko @ 2006-11-10 16:24 UTC (permalink / raw)
Hello,
I am trying to write a command that will convert all occurance of a
lower case character followed by an uppercase character (such as kA)
into a sequance of lowercase characters separated by an underscore.
So, kA would go to k_a
This is my attempt:
(defun camel-to-underline ()
(interactive)
(while (re-search-forward "[a-z][A-Z]")
(insert "_")
(downcase-region (point) (+ 1 (point))) ) )
The problem is that re-search-forward seems to capture the very next
character, irrespective whether the following one is uppercase or
lowercase.
What am I missing?
Thanks,
Mirko
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: What is wrong with this regexp search?
2006-11-10 16:24 What is wrong with this regexp search? Mirko
@ 2006-11-10 16:46 ` rgb
2006-11-10 16:50 ` Juanma Barranquero
[not found] ` <mailman.407.1163177433.2155.help-gnu-emacs@gnu.org>
2 siblings, 0 replies; 4+ messages in thread
From: rgb @ 2006-11-10 16:46 UTC (permalink / raw)
> The problem is that re-search-forward seems to capture the very next
> character, irrespective whether the following one is uppercase or
> lowercase.
case-fold-search is probably non-nil
Put a let someplace around your search.
Then it doesn't matter if it's on or off.
(let (case-fold-search)(re-search-forward "[a-z][A-Z]"))
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: What is wrong with this regexp search?
2006-11-10 16:24 What is wrong with this regexp search? Mirko
2006-11-10 16:46 ` rgb
@ 2006-11-10 16:50 ` Juanma Barranquero
[not found] ` <mailman.407.1163177433.2155.help-gnu-emacs@gnu.org>
2 siblings, 0 replies; 4+ messages in thread
From: Juanma Barranquero @ 2006-11-10 16:50 UTC (permalink / raw)
Cc: help-gnu-emacs
On 10 Nov 2006 08:24:53 -0800, Mirko <mvukovic@nycap.rr.com> wrote:
> This is my attempt:
>
> (defun camel-to-underline ()
> (interactive)
> (while (re-search-forward "[a-z][A-Z]")
> (insert "_")
> (downcase-region (point) (+ 1 (point))) ) )
>
> The problem is that re-search-forward seems to capture the very next
> character, irrespective whether the following one is uppercase or
> lowercase.
>
> What am I missing?
The variable `case-fold-search', I think.
Try with:
(defun camel-to-underline ()
(interactive)
(let (case-fold-search)
(while (re-search-forward "[a-z][A-Z]")
(insert "_")
(downcase-region (point) (+ 1 (point))))))
/L/e/k/t/u
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: What is wrong with this regexp search?
[not found] ` <mailman.407.1163177433.2155.help-gnu-emacs@gnu.org>
@ 2006-11-10 18:53 ` Mirko
0 siblings, 0 replies; 4+ messages in thread
From: Mirko @ 2006-11-10 18:53 UTC (permalink / raw)
Juanma Barranquero wrote:
> On 10 Nov 2006 08:24:53 -0800, Mirko <mvukovic@nycap.rr.com> wrote:
>
> > This is my attempt:
> >
> > (defun camel-to-underline ()
> > (interactive)
> > (while (re-search-forward "[a-z][A-Z]")
> > (insert "_")
> > (downcase-region (point) (+ 1 (point))) ) )
> >
> > The problem is that re-search-forward seems to capture the very next
> > character, irrespective whether the following one is uppercase or
> > lowercase.
> >
> > What am I missing?
>
> The variable `case-fold-search', I think.
>
> Try with:
>
> (defun camel-to-underline ()
> (interactive)
> (let (case-fold-search)
> (while (re-search-forward "[a-z][A-Z]")
> (insert "_")
> (downcase-region (point) (+ 1 (point))))))
>
> /L/e/k/t/u
Thank you to both of you. That was indeed the problem.
Mirko
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2006-11-10 18:53 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-11-10 16:24 What is wrong with this regexp search? Mirko
2006-11-10 16:46 ` rgb
2006-11-10 16:50 ` Juanma Barranquero
[not found] ` <mailman.407.1163177433.2155.help-gnu-emacs@gnu.org>
2006-11-10 18:53 ` Mirko
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).