[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [2nd attempt] What's the doc of replace-regexp-in-string saying ?
From: |
Tassilo Horn |
Subject: |
Re: [2nd attempt] What's the doc of replace-regexp-in-string saying ? |
Date: |
Wed, 08 Dec 2010 15:37:09 -0000 |
User-agent: |
Gnus/5.110011 (No Gnus v0.11) Emacs/24.0.50 (gnu/linux) |
bolega <gnuist006@gmail.com> writes:
>> In this doc, its not clear what the role of \' is ?
It does basically that what the docs say: it tells the function to
replace only the first or the last match.
,----[ (info "(elisp)Regexp Backslash") ]
| `\`'
| matches the empty string, but only at the beginning of the buffer
| or string being matched against.
|
| `\''
| matches the empty string, but only at the end of the buffer or
| string being matched against.
`----
Here are some examples.
--8<---------------cut here---------------start------------->8---
;; Replace all matches
(replace-regexp-in-string "\\(foo\\)" "bar" "foo foo")
==> "bar bar"
;; Replace only the match at the end of the string
(replace-regexp-in-string "\\(foo\\)\\'" "bar" "foo foo")
==> "foo bar"
;; Replace only the match at the beginning of the string
(replace-regexp-in-string "\\`\\(foo\\)" "bar" "foo foo")
==> "bar foo"
--8<---------------cut here---------------end--------------->8---
BTW: A great tool to experiment with functions is the interactive elisp
shell (M-x ielm RET).
Bye,
Tassilo
- What's the doc of replace-regexp-in-string saying ?, bolega, 2010/12/08
- [2nd attempt] What's the doc of replace-regexp-in-string saying ?, bolega, 2010/12/08
- Re: What's the doc of replace-regexp-in-string saying ?, Sidney Lambe, 2010/12/09
- Re: What's the doc of replace-regexp-in-string saying ?, Pascal J. Bourguignon, 2010/12/08
- Re: What's the doc of replace-regexp-in-string saying ?, Sidney Lambe, 2010/12/09
- Re: What's the doc of replace-regexp-in-string saying ?, Pascal J. Bourguignon, 2010/12/08
- Re: What's the doc of replace-regexp-in-string saying ?, Chris F.A. Johnson, 2010/12/08
- Re: What's the doc of replace-regexp-in-string saying ?, Stefan Monnier, 2010/12/08
- Re: What's the doc of replace-regexp-in-string saying ?, Pascal J. Bourguignon, 2010/12/08
- Re: What's the doc of replace-regexp-in-string saying ?, bolega, 2010/12/08