unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Re: What's the doc of replace-regexp-in-string saying ?
       [not found]     ` <slrniejrsu.1a7.sidneylambe@3f8s2dcr5.net>
@ 2010-11-22 10:53       ` Pascal J. Bourguignon
  2010-11-23 16:33         ` Stefan Monnier
  0 siblings, 1 reply; 5+ messages in thread
From: Pascal J. Bourguignon @ 2010-11-22 10:53 UTC (permalink / raw)
  To: help-gnu-emacs

Sidney Lambe <sidneylambe@somewhere.invalid> writes:

> On comp.unix.shell, Pascal J. Bourguignon <pjb@informatimago.com>
> wrote:
>
>> Sidney Lambe <sidneylambe@somewhere.invalid> writes:
>>
>>> On comp.unix.shell, bolega <gnuist006@gmail.com> wrote:
>>>
>>>> Hello All,
>>>
>>>
>>> comp.lang.lisp
>>
>> Better news:comp.emacs.help
>>
>
> Ah yes. I am vi (vanilla vi, not vim or elvis...) man myself, and had forgotten that emacs 
> used lisp. 
>
> I actually have never even tried emacs. Every description I've
> read really turns me off.
>
> It's really a textmode integrated desktop environment
> these days, isn't it?

No, it's a TEXT editor, but you are forbidden to type any character, or
read any character.  It only displays 3D animated little animals in a 3D
wonderworld, and you 'edit' your program by pushing those little 3D
animals around and enticing them doing things more or less palatable.

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
A bad day in () is better than a good day in {}.


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

* Re: [2nd attempt] What's the doc of replace-regexp-in-string saying ?
       [not found] ` <5a2270e2-889f-4d22-ba15-951a4c170671@o2g2000vbh.googlegroups.com>
@ 2010-11-22 16:27   ` Tassilo Horn
       [not found]   ` <slrniel543.gia.bill@lat.localnet>
  1 sibling, 0 replies; 5+ messages in thread
From: Tassilo Horn @ 2010-11-22 16:27 UTC (permalink / raw)
  To: help-gnu-emacs

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


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

* Re: [2nd attempt] What's the doc of replace-regexp-in-string saying ?
       [not found]   ` <slrniel543.gia.bill@lat.localnet>
@ 2010-11-22 18:32     ` Orivej Desh
  0 siblings, 0 replies; 5+ messages in thread
From: Orivej Desh @ 2010-11-22 18:32 UTC (permalink / raw)
  To: help-gnu-emacs

Bill Marcum <bill@lat.localnet> writes:

> On 2010-11-22, bolega <gnuist006@gmail.com> wrote:
>>
>> On Nov 21, 3:27 pm, bolega <gnuist...@gmail.com> wrote:
>>> Hello All,
>>>
>>> In this doc, its not clear what the role of \' is ?
>>>
>>>
>>> To replace only the first match (if any), make REGEXP match up to \'
>>> and replace a sub-expression, e.g.
>>>   (replace-regexp-in-string "\(foo\).*\'" "bar" " foo foo" nil nil 1)
>>>     => " bar foo"
>>
> This is off topic for comp.unix.shell, but it seems clear to me. If the 
> regexp didn't end with \', it would change " foo foo" to " bar bar".

Since matching is hungry, this is not the case:

     (replace-regexp-in-string "\\(foo\\).*\\'" "bar"
                               " foo foo" nil nil 1)
     " bar foo"

     (replace-regexp-in-string "\\(foo\\).*" "bar"
                               " foo foo" nil nil 1)
     " bar foo"

Moreover, I'm sure bolega has spotted an error in documentation.
Consider this:

     (replace-regexp-in-string "\\(foo\\).*\\'" "bar"
                                "foo foo\n foo foo" nil nil 1)
     "foo foo
      bar foo"

Documentation string assumed that `.' would match a newline.

\' matches an end of a string, unlike $ which matches both an end of a
string and an end of a line).  Without \' or with $ the last regexp
matches twice:

     (replace-regexp-in-string "\\(foo\\).*" "bar"
                                "foo foo\n foo foo" nil nil 1)
     "bar foo
      bar foo"

     (replace-regexp-in-string "\\(foo\\).*$" "bar"
                                "foo foo\n foo foo" nil nil 1)
     "bar foo
      bar foo"


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

* Re: What's the doc of replace-regexp-in-string saying ?
  2010-11-22 10:53       ` What's the doc of replace-regexp-in-string saying ? Pascal J. Bourguignon
@ 2010-11-23 16:33         ` Stefan Monnier
  2010-11-23 17:19           ` Pascal J. Bourguignon
  0 siblings, 1 reply; 5+ messages in thread
From: Stefan Monnier @ 2010-11-23 16:33 UTC (permalink / raw)
  To: help-gnu-emacs

> No, it's a TEXT editor

I beg to differ: Emacs has never been able to edit any text for me:
I've always had to do the editing myself.


        Stefan "still hoping"


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

* Re: What's the doc of replace-regexp-in-string saying ?
  2010-11-23 16:33         ` Stefan Monnier
@ 2010-11-23 17:19           ` Pascal J. Bourguignon
  0 siblings, 0 replies; 5+ messages in thread
From: Pascal J. Bourguignon @ 2010-11-23 17:19 UTC (permalink / raw)
  To: help-gnu-emacs

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> No, it's a TEXT editor
>
> I beg to differ: Emacs has never been able to edit any text for me:
> I've always had to do the editing myself.

It's all your fault.  
What are you waiting to write in emacs lisp the AI to do the editing for you?


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
A bad day in () is better than a good day in {}.


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

end of thread, other threads:[~2010-11-23 17:19 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <09bb11dd-b588-4b5c-8f8c-b31e2590599c@v23g2000vbi.googlegroups.com>
     [not found] ` <slrniejnhj.1a7.sidneylambe@3f8s2dcr5.net>
     [not found]   ` <874oba2egv.fsf@kuiper.lan.informatimago.com>
     [not found]     ` <slrniejrsu.1a7.sidneylambe@3f8s2dcr5.net>
2010-11-22 10:53       ` What's the doc of replace-regexp-in-string saying ? Pascal J. Bourguignon
2010-11-23 16:33         ` Stefan Monnier
2010-11-23 17:19           ` Pascal J. Bourguignon
     [not found] ` <5a2270e2-889f-4d22-ba15-951a4c170671@o2g2000vbh.googlegroups.com>
2010-11-22 16:27   ` [2nd attempt] " Tassilo Horn
     [not found]   ` <slrniel543.gia.bill@lat.localnet>
2010-11-22 18:32     ` Orivej Desh

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).