From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Jesper Harder Newsgroups: gmane.emacs.help Subject: Re: Regexp to match any character, including newline? Date: Sun, 05 Oct 2003 00:59:22 +0200 Organization: http://purl.org/harder/ Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Message-ID: References: NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1065309453 28769 80.91.224.253 (4 Oct 2003 23:17:33 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sat, 4 Oct 2003 23:17:33 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Oct 05 01:17:31 2003 Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1A5veV-0000Uv-00 for ; Sun, 05 Oct 2003 01:17:31 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.24) id 1A5vdn-0005LU-TD for geh-help-gnu-emacs@m.gmane.org; Sat, 04 Oct 2003 19:16:47 -0400 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!logbridge.uoregon.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!not-for-mail Original-Newsgroups: gnu.emacs.help X-Face: ^RrvqCr7c,P$zTR:QED"@h9+BTm-"fjZJJ-3=OU7.)i/K]<.J88}s>'Z_$r; List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.help:12989 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:12989 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) ")")) => "\\(?:(\\(?:.\\| \\)*and\\(?:.\\| \\)*[1-2][[:digit:]]\\{4\\}\\(?:.\\| \\)*)\\)"