In Gnu Emacs (I'm running V 24.3), I can capture a matching group like this:
M-x re-search-forward
RE search: \([0-9]+\)\.txt
... which finds a string with one or more digits followed by .txt
. But now I'd like to insert the string of digits (captured in group 1) in another buffer.
I'm guessing the answer is obvious, but it's eluding me. Any hints?
Use (match-string 1)
, to get the string matching the 1st subgroup.
This assumes that you have not changed the match data (e.g. by doing another search) since you did re-search-forward
.
See the Elisp manual, node Simple Match Data
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With