From: Kevin Rodgers <ihs_4664@yahoo.com>
Subject: Re: regexp newline issue
Date: Tue, 29 Nov 2005 11:23:48 -0700 [thread overview]
Message-ID: <dmi6bm$k01$1@sea.gmane.org> (raw)
In-Reply-To: <yzlmzjplh2g.fsf@rgassoc-cs.local>
Christopher C. Stacy wrote:
> I want to search for a string like "foo bar",
> but there might be whitespace (even newlines)
> between any of the characters.
>
> Given the string "foo bar", I tried constructing a regexp by
>
> (replace-regexp-in-string "\\(.\\)"
> "[\040\011\012\015]*\\1"
> "foo bar")
>
> but that doesn't quite do it.
>
> By the way, I originally tried whitespace syntax "\\s-"
> rather than character alternatives, but that seemed to
> work even less well. Also, I am using an older emacs
> that does not seem to have the named character classes.
The whitespace syntax class depends on the current syntax table, which
is specific to the buffer's major mode (and can even be overridden by
text properties in the buffer).
BTW, I think this is more readable than the octal notation: "[ \t\n\r]"
> In particular, the above [tab,LF,CR] hack finds #1 and #3,
> but not #2, in the following examples:
>
> ----------
>
> 1. foo bar
>
> 2. foo
> bar
>
> -or-
>
> 3. fo
> o ba
> r
> ----------
That's because the regexp you generate requires each of the characters
in the string to be present, including the space between the second "o"
and "b". As John Paul Wellington showed, you should ignore the
whitespace characters in the string when generating the regexp.
--
Kevin Rodgers
prev parent reply other threads:[~2005-11-29 18:23 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-11-28 1:03 regexp newline issue Christopher C. Stacy
2005-11-28 4:44 ` John Paul Wallington
2005-11-28 5:22 ` John Paul Wallington
[not found] ` <mailman.17016.1133155392.20277.help-gnu-emacs@gnu.org>
2005-12-01 4:38 ` Stefan Monnier
2005-11-29 18:23 ` Kevin Rodgers [this message]
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='dmi6bm$k01$1@sea.gmane.org' \
--to=ihs_4664@yahoo.com \
/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.
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).