[Top][All Lists]

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

Re: Regexp to match any character, including newline?

From: Jesper Harder
Subject: Re: Regexp to match any character, including newline?
Date: Sun, 05 Oct 2003 00:59:22 +0200
User-agent: Gnus/5.1003 (Gnus v5.10.3) Emacs/21.3.50 (gnu/linux)

Joe Fineman <> writes:

> It is sometimes a nuisance that "." in a regexp does not match
> newlines.  For example, I want a regexp for text in parentheses that
> contains the word "and" followed (anywhere) by a date.
>   (.+ and .+ [1-2][0-9][0-9][0-9].+)
> works only if the expression happens to be on one line.  I have tried
> [^ ] with the space replaced by an unlikely character such as ASCII
> 000; that seems to work in isolation, but when I substitute it for
> . in the above regexp, the result misbehaves, missing all the right
> matches & finding the odd wrong one.  Is there an obvious solution to
> this problem?

You can use "\\(?:.\\|\n\\)+" to match _anything_ including newlines.

Also, look at the very cool 'rx' package, which provides a much nicer
syntax for regexps than the usual line noise.  For instance:

(rx (and "(" (* anything) "and" (* anything)
         (in "1-2") (repeat 4 digit) (* anything) ")"))

reply via email to

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