Re: Regex teaser

2013-12-05 Thread Smylers
Yesterday I wrote: > Paul Makepeace writes: > > > On Tue, Dec 3, 2013 at 5:03 PM, Mark Fowler > > wrote: > > > > > On Tue, Dec 3, 2013 at 6:54 PM, Paul Makepeace > > > wrote: > > > > > > > $ perl -le '($a = "aabbb") =~ s/b*$/c/g; print $a' > > > > > > This is where tools like Regexp::Debugger

Re: Regex teaser

2013-12-04 Thread Yitzchak Scott-Thoennes
On Tue, Dec 3, 2013 at 11:55 PM, Paul Makepeace wrote: > Construct an elegant* regex (in perl!) to ensure the end of the string > contains "string": > > is(fqdn('foo'), 'foo.example.com') > is(fqdn('foo.example.com'), 'foo.example.com') Maybe I'm just slow, but I see no relation between that task

Re: Regex teaser

2013-12-04 Thread Smylers
Matt Lawrence writes: > It looks like Python has decided that a zero-width match cannot > immediately follow a non-zero-width match. Thanks. That sounds like a special-case exception to me, increasing the complexity of understanding how patterns match. But in practice it might be less surprisin

Re: Regex teaser

2013-12-04 Thread Matt Lawrence
On 04/12/13 10:15, Smylers wrote: I agree the behaviour isn't immediately obvious. But it does make sense when thinking about what each component means separately. So what does seem bug-like to me is the Python behaviour — can anybody explain that? It looks like Python has decided that a zero-w

Re: Regex teaser

2013-12-04 Thread Smylers
Paul Makepeace writes: > On Tue, Dec 3, 2013 at 5:03 PM, Mark Fowler wrote: > > > On Tue, Dec 3, 2013 at 6:54 PM, Paul Makepeace > > wrote: > > > > > $ perl -le '($a = "aabbb") =~ s/b*$/c/g; print $a' > > > > This is where tools like Regexp::Debugger shine. Running > > > > perl -le 'use Regex

Re: Regex teaser

2013-12-04 Thread Matt Lawrence
On 04/12/13 07:55, Paul Makepeace wrote: On Tue, Dec 3, 2013 at 5:03 PM, Mark Fowler wrote: On Tue, Dec 3, 2013 at 6:54 PM, Paul Makepeace wrote: $ perl -le '($a = "aabbb") =~ s/b*$/c/g; print $a' This is where tools like Regexp::Debugger shine. Running perl -le 'use Regexp::Debugger; (

Re: Regex teaser

2013-12-04 Thread Fred Youhanaie
On 04/12/13 07:55, Paul Makepeace wrote: * I realise this is hilariously open to interpretation but you'll know what I mean either way http://geek-and-poke.com/geekandpoke/2013/12/3/yesterdays-regex ;-)

Re: Regex teaser

2013-12-04 Thread Paul Makepeace
On Tue, Dec 3, 2013 at 5:03 PM, Mark Fowler wrote: > On Tue, Dec 3, 2013 at 6:54 PM, Paul Makepeace wrote: > >> $ perl -le '($a = "aabbb") =~ s/b*$/c/g; print $a' > > This is where tools like Regexp::Debugger shine. Running > > perl -le 'use Regexp::Debugger; ($a = "aabbb") =~ s/b*$/c/g; print

Re: Regex teaser

2013-12-03 Thread Mark Fowler
On Tue, Dec 3, 2013 at 6:54 PM, Paul Makepeace wrote: > $ perl -le '($a = "aabbb") =~ s/b*$/c/g; print $a' This is where tools like Regexp::Debugger shine. Running perl -le 'use Regexp::Debugger; ($a = "aabbb") =~ s/b*$/c/g; print $a' Shows exactly why it gives the output it does (if you hit

Re: Regex teaser

2013-12-03 Thread Simon Cozens
On 04/12/2013 08:54, Paul Makepeace wrote: $ perl -le '($a = "aabbb") =~ s/b*$/c/g; print $a' Why... oh. That's clever. Yes. For those like me who are slow and can't immediately see why that does what it does, here are some hints: What does perl -le '($a = "aabbb") =~ s/b+$/c/g; print $a' d

Re: Regex teaser

2013-12-03 Thread James Laver
On 3 Dec 2013, at 23:54, Paul Makepeace wrote: > What does this output? > > $ perl -le '($a = "aabbb") =~ s/b*$/c/g; print $a’ You can tell you’ve been writing perl too long when you know what that’s going to do and why :( Here’s your example modified to exhibit my favourite regex madness. Ca

Re: Regex teaser

2013-12-03 Thread Yitzchak Scott-Thoennes
On Tue, Dec 3, 2013 at 3:54 PM, Paul Makepeace wrote: > What does this output? > > $ perl -le '($a = "aabbb") =~ s/b*$/c/g; print $a' > > Cunning multilinguists may also answer the same question of these, > (which nominally do the same thing) > > $ ruby -e 'p "aabbb".gsub(/b*$/, "c")' > > $ python

Regex teaser

2013-12-03 Thread Paul Makepeace
What does this output? $ perl -le '($a = "aabbb") =~ s/b*$/c/g; print $a' Cunning multilinguists may also answer the same question of these, (which nominally do the same thing) $ ruby -e 'p "aabbb".gsub(/b*$/, "c")' $ python -c "import re; print re.sub(r'b*$', 'c', 'aabbb')" Enjoy... Paul