[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: regexp question
From: |
Florian Kaufmann |
Subject: |
Re: regexp question |
Date: |
27 Sep 2006 00:58:10 -0700 |
User-agent: |
G2/1.0 |
> i want to replace a block beginning with <column_right> and ending with
> </column_right>, with a variable number of lines between with another
> text block. ext block with a regular expression?
I would use:
<column_right>\(.\|^J\)*?</column_right>
Where the ^J results from pressing C-q C-j.
The details: Since the dot . does much any character but the newline, I
use the construct \(.\|^J\) which now matches really any character. *?
is the lazy version of the greedy *. Meaning that as few as possible
are selected. This prevents from selecting too much. Only * instead of
*? would much both of the following lines instead of only one.
<column_right>line1</column_right>
<column_right>line2</column_right>
However, my regex fails to match nested tags. In the following example
<column_right><column_right></column_right></column_right>
the match is
<column_right><column_right></column_right>
which is not what you want. I don't know how to make a regular
expression which would also support this case. I'm sure you would find
the answer in the book "Mastering regular expressions"
Flo
RE: replace a textblock in multiple files, Jay Bingham, 2006/09/27