[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to combine these two regular expressions
From: |
Jambunathan K |
Subject: |
Re: How to combine these two regular expressions |
Date: |
Mon, 13 Aug 2012 00:14:16 +0530 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.1.50 (gnu/linux) |
You should provide a human-readable description of what the regexes are
trying to do. Have you tried:
C-h f regexp-opt RET
Cecil Westerhof <Cecil@decebal.nl> writes:
> I was asked by someone for a regular expression that could combine
> several search patterns, so that a file only needs to be scanned ones
> and not several times. I was partly successful, but I still need two
> passes.
>
> I now have the following code:
> (defun dcbl-search-heading ()
> (interactive)
> (re-search-forward "\\(.
> \\)\\(
>
> \\)\\(.+
> \\)\\(
> ?.+
> \\)" nil t)
> (replace-match "\\1
> #heading#
> \\4"))
>
> (defun dcbl-search-heading2 ()
> (interactive)
> (re-search-forward "\\(.
> \\)\\(
> \\)\\(.+
> \\)\\(\\\(.+
> \\\)+\\)" nil t)
> (replace-match "\\1
> #heading#
> \\4"))
>
> Is there a way to combine those regular expressions to one?
>
> By the way, if the used expressions could be optimised, let me know. I
> do not make them often, thus maybe I do things sub-optimal here.
--