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

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

How to combine these two regular expressions


From: Cecil Westerhof
Subject: How to combine these two regular expressions
Date: Sun, 12 Aug 2012 16:57:18 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux)

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.

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof


reply via email to

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