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

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

Re: Regexp to match any character, including newline?


From: Stefan Monnier
Subject: Re: Regexp to match any character, including newline?
Date: Sat, 04 Oct 2003 22:46:58 GMT
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3.50

> 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.

(re-search-forward "([^\000]+and[^\000]+[12][0-9]\\{3\\}[^\000]+)")
seems to work just fine here.  Note that if you enter the RE interactively,
you have to use [ ^ C-q 0 RET ] and not [ ^ \ 0 0 0 ] (which would
match any char except for backslash and 0).

> Is there an obvious solution to this problem?

use \(.\|\n\) which matches any character.


        Stefan


reply via email to

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