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

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

Re: Tricky Regexp - How to insert a marker every 3rd number in a sequenc


From: Emanuel Berg
Subject: Re: Tricky Regexp - How to insert a marker every 3rd number in a sequence that begins with a certain delimiter
Date: Sat, 06 Jun 2015 20:15:07 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)

gnuist006@gmail.com writes:

> 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

I don't have a lot of confidence this can be done with
regexps. Even if it can (?), say you want to change
some detail or do something else (but similar) next
time? Oh, no! More regexps!

Instead you will be helped by a parser to crunch and
tokenize the input string, then some (small) program
to act on them tokens and output the output string
accordingly. In particular, one such token would be
"3-SEQ" (or something like that) representing the
sequences you describe (as they are equivalent no
matter how many Ns, just as they are multiples of 3).
Then it would just be a matter of checking "is the
current token a 3-SEQ?" - "if so, insert Z!"

I don't know if the parser and compiler compilers
tools are easier for this or if it is easier to just
do it in Lisp (Elisp). Probably if you already know
them tools that would be more easy. If you don't know
them Lisp would be just as good a bid.

-- 
underground experts united
http://user.it.uu.se/~embe8573


reply via email to

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