regexp:(g)sub buglet?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

regexp:(g)sub buglet?

Hal Snyder-2
(on freebsd 4-8)

Third result doesn't look right to me; sub and gsub act the same.

/usr/foo/otp/otp_src_R10B-7>bin/erl
Erlang (BEAM) emulator version 5.4.9 [source]

Eshell V5.4.9  (abort with ^G)

1> regexp:gsub("foo","o$","Z").
{ok,"foZ",1}

2> regexp:gsub("foo","^","Z").
{ok,"Zfoo",1}

3> regexp:gsub("foo","$","Z").
{ok,"foo",0}



Reply | Threaded
Open this post in threaded view
|

regexp:(g)sub buglet?

Bengt Kleberg-4
On 2005-11-29 01:18, Hal Snyder wrote:

> 3> regexp:gsub("foo","$","Z").
> {ok,"foo",0}

before sam (http://plan9.bell-labs.com/sys/doc/sam/sam.html, first use
of strucural regular expressions) most (all?) regular expressions used
'\n' as end of string. try:

regexp:gsub("foo\n","$","Z").


bengt


Reply | Threaded
Open this post in threaded view
|

regexp:(g)sub buglet?

Timur Irmatov-2
On 11/29/05, Bengt Kleberg <bengt.kleberg> wrote:

> On 2005-11-29 01:18, Hal Snyder wrote:
>
> > 3> regexp:gsub("foo","$","Z").
> > {ok,"foo",0}
>
> before sam (http://plan9.bell-labs.com/sys/doc/sam/sam.html, first use
> of strucural regular expressions) most (all?) regular expressions used
> '\n' as end of string. try:
>
> regexp:gsub("foo\n","$","Z").

perl and python behave differently:

perl -e '$a="foo"; $a =~ s/$/Z/; print "$a\n"'

prints fooZ.


--
Timur Irmatov, xmpp:thor


Reply | Threaded
Open this post in threaded view
|

regexp:(g)sub buglet?

Michał Ptaszek
On Tue, Nov 29, 2005 at 03:03:18PM +0500, Timur Irmatov wrote:

> On 11/29/05, Bengt Kleberg <bengt.kleberg> wrote:
> > On 2005-11-29 01:18, Hal Snyder wrote:
> >
> > > 3> regexp:gsub("foo","$","Z").
> > > {ok,"foo",0}
> >
> > before sam (http://plan9.bell-labs.com/sys/doc/sam/sam.html, first use
> > of strucural regular expressions) most (all?) regular expressions used
> > '\n' as end of string. try:
> >
> > regexp:gsub("foo\n","$","Z").
>
> perl and python behave differently:
>
> perl -e '$a="foo"; $a =~ s/$/Z/; print "$a\n"'
>
> prints fooZ.
>
>
> --
> Timur Irmatov, xmpp:thor
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

from the regexp.html documentation on my R10B-8 system

"
^
    matches the beginning of a string.
$
    matches the end of a string.
"

 ...


"To make these functions easier to use, in combination with the
 function io:get_line which terminates the input line with a new
 line, the $ characters also matches a string ending with "...\n".
 The following examples define Erlang data types:"


To me, the use of the phrase
' ... also matches a string ending with "...\n". '  lead me to think
that "Z" should be appended in either case (with or without "\n" at
end of string).



~Michael