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

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

Regexp: match any character including newline


From: Yuri Khan
Subject: Regexp: match any character including newline
Date: Wed, 16 Oct 2013 21:42:54 +0700

Hello All,

I’m doing regexp replacements on a hard-wrapped XHTML-alike. Here’s an
original fragment:

===
<tr><td><pre><code>X(n, t)
X a(n, t)</code></pre></td><td></td>
    <td><requires><p><code>T</code> shall be
        <concept>Copy&shy;Insert&shy;able</concept> into
        <code>X</code>.</p></requires>
        <p>post: <code>distance(begin(), end()) == n</code></p>
        <p>Constructs a sequence container with <code>n</code> copies
        of <code>t</code></p></td></tr>
===

Here’s what I need to turn it into:

===
<expression><pre><code>X(n, t)
X a(n, t)</code></pre></expression>
<return_type></return_type>
<assertion_note><requires><p><code>T</code> shall be
        <concept>Copy&shy;Insert&shy;able</concept> into
        <code>X</code>.</p></requires>
        <p>post: <code>distance(begin(), end()) == n</code></p>
        <p>Constructs a sequence container with <code>n</code> copies
        of <code>t</code></p></assertion_note>
===

To this end, I want to do a regexp replace of:

===
<tr><td>\(.*?\)</td><td>\(.*?\)</td>
    <td>\(.*?\)</td></tr>
===

with

===
<expression>\1</expression>
<return_type>\2</return_type>
<assertion_note>\3</assertion_note>
===

except that “.” needs to match any character including newline.

I know the obvious solution: instead of “.”, use the following monstrosity:

===
\(?:.\|
\)
===

However, I find that very cumbersome to type, especially since I have
to press C-q C-j in between.

Is there a way to make “.” match newline too, or is there an easier
way to match any character including newline? (I don’t want to limit
myself to [:ascii:] as there are also Unicode-specific dashes.)

For now, I’ve devised a workaround of using [^@] where @ is a
character that does not occur in the text. Maybe [^^] since it’s
easier to type and looks cute :)



reply via email to

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