unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Jesper Harder <harder@myrealbox.com>
Subject: Re: Regexp to match any character, including newline?
Date: Sun, 05 Oct 2003 00:59:22 +0200	[thread overview]
Message-ID: <m33ce87gol.fsf@defun.localdomain> (raw)
In-Reply-To: wkisn4mzkx.fsf@TheWorld.com

Joe Fineman <jcf@TheWorld.com> 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\\}\\(?:.\\|
\\)*)\\)"

  parent reply	other threads:[~2003-10-04 22:59 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-10-04 22:02 Regexp to match any character, including newline? Joe Fineman
2003-10-04 22:46 ` Stefan Monnier
2003-10-04 22:59 ` Jesper Harder [this message]
2003-10-05  7:09   ` Martin Stone Davis
     [not found]   ` <mailman.1130.1065337789.21628.help-gnu-emacs@gnu.org>
2003-10-05 20:35     ` Jesper Harder
2003-10-05 21:45 ` Joe Fineman
2003-10-06  8:20 ` Gian Uberto Lauri

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=m33ce87gol.fsf@defun.localdomain \
    --to=harder@myrealbox.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).