[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Tricky Regexp - How to insert a marker every 3rd number in a sequence th
From: |
gnuist006 |
Subject: |
Tricky Regexp - How to insert a marker every 3rd number in a sequence that begins with a certain delimiter |
Date: |
Sat, 6 Jun 2015 10:44:53 -0700 (PDT) |
User-agent: |
G2/1.0 |
tricky regexp
How to insert a marker every 3rd number in a sequence that begins with a
certain delimiter, and ends with a certain delimiter and its length is a
multiple of three?
I want to isolate sequences like this in a text and to work on them only.
Given:-
text
text
BEGIN N N N END
text BEGIN N N N N N N END
some text BEGIN N N N N N N N N N END
text
N N N N N N N
text
The sequences I want to work on start with BEGIN and end with END with exact
multiple of 3 B's in between with only single space. I want to place a newline
before every 3 B's. So the above text would transform to
text
text
BEGIN
N N N
Z
text BEGIN
N N N
N N N
Z
some text BEGIN
N N N
N N N
N N N
Z
text
N N N N N N N
text
More accurately, in a "BEGIN N N N N N N N N N END" type sequence, I want to
insert a \n before every N whose cardinality is 3n where n=0,1,2,... and the
first N has cardinality 0. I also want to insert a \n righ before such a END.
My efforts:
(replace-regexp "BEGIN \\([0-9]\\) \\([0-9]\\) \\([0-9]\\) END" "BEGIN \n\\1
\\2 \\3 \nEND")
- Tricky Regexp - How to insert a marker every 3rd number in a sequence that begins with a certain delimiter,
gnuist006 <=
Message not available