Subject: REGEXP package

From: Erik Arneson <[email-masked]>
Date: Fri, 30 Jul 1999 11:49:16 -0700 (PDT)

Howdy everybody,

I'm trying to use the REGEXP package to port replace-in-string from
XEmacs, and I've gotten pretty far.  The hurdle I've been unable to
clear, however, is pulling specific matches from a regexp::match result.

For example, if I do this:

(REGEXP::MATCH "\\(foo\\)" "a foo string with two foos")

How do I discern between the first match and the second match?  They
should be grouped somehow, but I'm not sure which function I can use to
find this.  Is grouping implemented in the REGEXP package?

-- 
# Erik Arneson      [email-masked]    Webring Software Engineer #
# Yahoo! Inc.      PGP ID: 1024/6EE28A05        (541) 482-3000x105 #
# "There's such a fine line between stupid and clever." Spinal Tap #

---

From: Bruno Haible <[email-masked]>
Date: Fri, 30 Jul 1999 21:11:30 +0200 (MET DST)

Erik Arneson <[email-masked]> writes:

> How do I discern between the first match and the second match?

The REGEXP module returns only the first match. After you got and digested
it, you can call REGEXP:MATCH with the :START keyword.

  (setq pattern "\\(foo\\)")
  (setq string "a foo string with two foos")
  (let ((index 0))
    (loop
      (let ((m (regexp:match pattern string :start index)))
        (unless m (return))
        (print m)
        (setq index (regexp:match-end m))
  ) ) )

Bruno