* Word boundary with regular expression
@ 2005-09-27 12:11 fede (sent by Nabble.com)
0 siblings, 0 replies; 5+ messages in thread
From: fede (sent by Nabble.com) @ 2005-09-27 12:11 UTC (permalink / raw)
[-- Attachment #1.1: Type: text/plain, Size: 596 bytes --]
Hi!
I have the following problem: I'm programming in C language and I'd like
to substitute every occurence of "my_type" with "another_type". So I'd like
"my_type *mine;" to become "another_type *mine;" and so on, but NOT
"my_type_2 *mine;" to become "another_type_2 *mine;"! I've tried the following:
(query-replace-regexp "\\bmy_type\\b" "another_type" nil nil nil)
but the problem is that \b seems to include words terminating with '_'...
any idea?
Thanks!
--
Sent from the Emacs - Help forum at Nabble.com:
http://www.nabble.com/Word-boundary-with-regular-expression-t350272.html#a970191
[-- Attachment #1.2: Type: text/html, Size: 769 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] 5+ messages in thread
* Re: Word boundary with regular expression
[not found] <mailman.8819.1127823405.20277.help-gnu-emacs@gnu.org>
@ 2005-09-27 13:13 ` Anselm Helbig
2005-09-27 15:25 ` Johan Bockgård
2005-09-28 6:48 ` fede (sent by Nabble.com)
0 siblings, 2 replies; 5+ messages in thread
From: Anselm Helbig @ 2005-09-27 13:13 UTC (permalink / raw)
At Tue, 27 Sep 2005 05:11:35 -0700 (PDT),
"fede (sent by Nabble.com)" <lists@nabble.com> wrote:
> I have the following problem: I'm programming in C language and I'd like
> to substitute every occurence of "my_type" with "another_type". So I'd like
> "my_type *mine;" to become "another_type *mine;" and so on, but NOT
> "my_type_2 *mine;" to become "another_type_2 *mine;"! I've tried the following:
>
> (query-replace-regexp "\\bmy_type\\b" "another_type" nil nil nil)
>
> but the problem is that \b seems to include words terminating with '_'...
> any idea?
you're right, in emacs' c-mode, `_' is not thought to be part of a
`word', it's part of a `symbol'. this setting is made in the syntax
table, see (info "(Emacs)Syntax") for more information about it.
so you can either change the syntax table (just for the current
buffer) by issuing a command like the following:
M-: (modify-syntax-entry ?_ "w")
from the buffer you're editing your c-file in. this means, put the
character "_" in the "w"ord-class. your original regex should work
then.
an alternative would be to check for whitespace in your regex, like
this (untested):
(query-replace-regexp "\\bmy_type\\(\\s \\)" "another_type\\1" nil nil nil)
not nice, but should work as well.
i didn't yet fiddle much with syntax-tables myself, so i don't know if
there would be any ill side-effects if you changed the syntax-table
for c-mode permanently.
HTH,
anselm
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Word boundary with regular expression
2005-09-27 13:13 ` Word boundary with regular expression Anselm Helbig
@ 2005-09-27 15:25 ` Johan Bockgård
2005-09-28 6:48 ` fede (sent by Nabble.com)
1 sibling, 0 replies; 5+ messages in thread
From: Johan Bockgård @ 2005-09-27 15:25 UTC (permalink / raw)
Anselm Helbig <anselm@chemie.fu-berlin.de> writes:
> you're right, in emacs' c-mode, `_' is not thought to be part of a
> `word', it's part of a `symbol'.
BTW, Emacs 22 will have constructs for matching symbol boundaries,
`\_<' and `\_>'.
--
Johan Bockgård
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Word boundary with regular expression
2005-09-27 13:13 ` Word boundary with regular expression Anselm Helbig
2005-09-27 15:25 ` Johan Bockgård
@ 2005-09-28 6:48 ` fede (sent by Nabble.com)
2005-10-07 1:05 ` Ian Zimmerman
1 sibling, 1 reply; 5+ messages in thread
From: fede (sent by Nabble.com) @ 2005-09-28 6:48 UTC (permalink / raw)
[-- Attachment #1.1: Type: text/plain, Size: 164 bytes --]
It works fine! Thanks!!!
Fede
--
Sent from the Emacs - Help forum at Nabble.com:
http://www.nabble.com/Word-boundary-with-regular-expression-t350272.html#a979253
[-- Attachment #1.2: Type: text/html, Size: 217 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] 5+ messages in thread
* Re: Word boundary with regular expression
2005-09-28 6:48 ` fede (sent by Nabble.com)
@ 2005-10-07 1:05 ` Ian Zimmerman
0 siblings, 0 replies; 5+ messages in thread
From: Ian Zimmerman @ 2005-10-07 1:05 UTC (permalink / raw)
fede> It works fine! Thanks!!!
You can also change the syntax table temporarily, for just one expression.
See the online help for `with-syntax-table'
--
"It's not true or not." A reality show producer (real quote)
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2005-10-07 1:05 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <mailman.8819.1127823405.20277.help-gnu-emacs@gnu.org>
2005-09-27 13:13 ` Word boundary with regular expression Anselm Helbig
2005-09-27 15:25 ` Johan Bockgård
2005-09-28 6:48 ` fede (sent by Nabble.com)
2005-10-07 1:05 ` Ian Zimmerman
2005-09-27 12:11 fede (sent by Nabble.com)
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).