From: Anselm Helbig <anselm@chemie.fu-berlin.de>
Subject: Re: Word boundary with regular expression
Date: Tue, 27 Sep 2005 15:13:54 +0200 [thread overview]
Message-ID: <87mzly3b71.wl@nospam.anselm.chemie.fu-berlin.de> (raw)
In-Reply-To: <mailman.8819.1127823405.20277.help-gnu-emacs@gnu.org>
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
next parent reply other threads:[~2005-09-27 13:13 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <mailman.8819.1127823405.20277.help-gnu-emacs@gnu.org>
2005-09-27 13:13 ` Anselm Helbig [this message]
2005-09-27 15:25 ` Word boundary with regular expression 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)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87mzly3b71.wl@nospam.anselm.chemie.fu-berlin.de \
--to=anselm@chemie.fu-berlin.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.