all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Elisp:  get word(s) from an re-match
@ 2015-03-26 13:20 Glen Stark
  2015-03-26 13:58 ` tomas
  0 siblings, 1 reply; 2+ messages in thread
From: Glen Stark @ 2015-03-26 13:20 UTC (permalink / raw
  To: help-gnu-emacs

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

The goal is to write a refactoring script that takes old iterator loops 
and replaces them with for (auto x : foo), so I'd like to have the name 
of itr and the object being iterated over.

I'm competent enough with regex's to write the regex, and replace with \1 
and \2, which would get me through the auto statement, but I want to 
store the name of itr in a variable, so I can replace occurences of itr  
in the body of the code with the new auto variable.

Can somone point me in the right direction?  A simple example that 
extracts a string out of a regex match and returns it into a variable 
would be fantastic.

Many thanks,

Glen


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

* Re: Elisp:  get word(s) from an re-match
  2015-03-26 13:20 Elisp: get word(s) from an re-match Glen Stark
@ 2015-03-26 13:58 ` tomas
  0 siblings, 0 replies; 2+ messages in thread
From: tomas @ 2015-03-26 13:58 UTC (permalink / raw
  To: Glen Stark; +Cc: help-gnu-emacs

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



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

end of thread, other threads:[~2015-03-26 13:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-03-26 13:20 Elisp: get word(s) from an re-match Glen Stark
2015-03-26 13:58 ` tomas

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.