all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Emanuel Berg <embe8573@student.uu.se>
To: help-gnu-emacs@gnu.org
Subject: Re: Tricky Regexp - How to insert a marker every 3rd number in a sequence that begins with a certain delimiter
Date: Sun, 07 Jun 2015 00:14:37 +0200	[thread overview]
Message-ID: <871tho4h82.fsf@debian.uxu> (raw)
In-Reply-To: mailman.4479.1433617759.904.help-gnu-emacs@gnu.org

John Mastro <john.b.mastro@gmail.com> writes:

> Is there a particular reason you want/need to use
> a (single) regular expression? It doesn't seem like
> a good fit to me. Unless you're somehow restricted
> to a single `replace-regexp', you may as well use
> more of Emacs's toolbox.
>
> Here's some quick-and-dirty Lisp (which, of course,
> uses regular expressions)

That's what I meant as well but you put it better.
You (the OP) should use BOTH Lisp and regexps!

> that works on your example but would need more work
> and refinement to serve your general purpose.

Are you sure there is one? :)

The only thing that might not be immediately obvious
from the code is the use of `re-search-forward' and
then `match-end'. re-search-forward with NOERROR (3rd
argument) supplied as t will return nil if there is no
hit. That will cause the loop to terminate.

While there are hits, match-end will return the
"position of end of text matched by last search", but
this isn't from the re-search-forward search but from
the `looking-at' "search".

Then the same mechanisms are at work with
`replace-match'.

And this general method is a good one! Search for
a regexp, then examine it (an easy fetch as the search
hit is stored), then insert or operate on it to
produce the desired output. Repeat until done.

Just add water!

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


      parent reply	other threads:[~2015-06-06 22:14 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=871tho4h82.fsf@debian.uxu \
    --to=embe8573@student.uu.se \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.