[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Elisp: get word(s) from an re-match
From: |
tomas |
Subject: |
Re: Elisp: get word(s) from an re-match |
Date: |
Thu, 26 Mar 2015 14:58:31 +0100 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Thu, Mar 26, 2015 at 01:20:57PM +0000, Glen Stark wrote:
> Hi everyone, I guess this is pretty trivial, but I'm struggling a
> little. Consider the following:
>
> for ( Foo::iterator itr = foo.begin() ; itr != foo.end(); ++foo)
>
> I want to to a regex search within elisp for this pattern, and extract
> into variables "foo" and "itr".
You want to look into the function match-data abd friends.
For example, (match-string 3) gives you the part matched by the third
parenthesis in your regexp in the current buffer (if you're matching
against a string `str', you'd have to write (match-string 3 str).
Note that this gets you the text properties too - if you want to have
them filtered, you'd use (match-string-no-properties ...).
Hope that helps.
- -- t
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)
iEYEARECAAYFAlUUEIcACgkQBcgs9XrR2kaCLwCePZtyTz4xEKeSRJY31ESGURT7
j9MAniTKoWSJT5crzgBQ5iFTXEsCiuuP
=6Ltb
-----END PGP SIGNATURE-----