all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Tricky Regexp - How to insert a marker every 3rd number in a sequence that begins with a certain delimiter
@ 2015-06-06 17:44 gnuist006
  2015-06-06 18:15 ` Emanuel Berg
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: gnuist006 @ 2015-06-06 17:44 UTC (permalink / raw)
  To: help-gnu-emacs

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")



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-06-07  2:46 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-06-06 17:44 Tricky Regexp - How to insert a marker every 3rd number in a sequence that begins with a certain delimiter gnuist006
2015-06-06 18:15 ` Emanuel Berg
2015-06-06 19:08 ` John Mastro
     [not found]   ` <CAF=27p0sY6oPo=Hcj1uZn2-ZSb5tiLQDVV3YHjZdXQVZH2VSUA@mail.gmail.com>
     [not found]     ` <CAOj2CQSLKKxS1xT1nWLe3mP9XaypddXux7F=9tnT_jiMgN+CXA@mail.gmail.com>
2015-06-07  0:57       ` gnu ist
2015-06-07  2:46         ` John Mastro
     [not found] ` <mailman.4479.1433617759.904.help-gnu-emacs@gnu.org>
2015-06-06 22:14   ` Emanuel Berg

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.