help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: regexp newline issue


From: John Paul Wallington
Subject: Re: regexp newline issue
Date: Mon, 28 Nov 2005 05:22:54 +0000
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (windows-nt)

I 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.
>
> I think you wanna zap all the whitespace chars from your "foo bar"
> string first (eg: so that it's "foobar") before doing the
> `replace-regexp-in-string' hack on it.

Hm.  If you do want to match on the whitespace within the string
then maybe something like this would do:

(defun cons-up-regexp (string)
  (mapconcat (lambda (char)
               (if (memq char '(32 9 10 13))
                   "[\040\011\012\015]"
                 (format "[\040\011\012\015]*%c" char)))
             string nil))




reply via email to

[Prev in Thread] Current Thread [Next in Thread]