Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

RE: Re: ^x* vs x*$

by tye (Sage)
on Aug 19, 2000 at 22:02 UTC ( [id://28655]=note: print w/replies, xml ) Need Help??


in reply to Re: ^x* vs x*$
in thread ^x* vs x*$

When this second item has come up before, it has been defended as being the correct behavior. The more general case is that when a regex can match a zero-width string, it is possible for multiple matches to end at the same point.

Another example is:

$str= "ababa"; $str =~ s/a*/x/g; print "$str\n"

which produces

xxbxxbxx

This is because we start at position 0 and match "a", leaving us a position 1. At position 1 we match "", leaving us at position 2 (we've already started at position 1 so we don't start there again, even though our match ended at position 1). At pos 2 we match "a", at pos 3 we match "", etc.

But this is a bit counter intuative. In fact, sed doesn't have this "quirk". So it might be a good idea to disallow zero-width matches that start (and therefore end) at the point where the previous match ended.

But that raises the ugly spectre of backward compatability... My current feeling is that "we" should "fix" this but provide a way to get the old behavior to ease the burdon of backward compatability (though no suitable syntax/feature for doing that springs to mind). I suspect a lack of to-its will cause the current behavior to remain until someone feels strong enough about it to champion its cause.

        - tye (but my friends call me "Tye")

Replies are listed 'Best First'.
RE (tilly) 3: ^x* vs x*$
by tilly (Archbishop) on Aug 20, 2000 at 06:16 UTC
    Very interesting. I can believe that happened.

    Still looks to me like a bug.

    perl -e '$str = "Hello World\n"; $str =~ s/\r?\n?$/\n/g; print $str;'
    Where did the second return come from?

    At the least after matching $ you should not match a zero-width assertion at that point again. IMHO and all that.

    I will send that bug report in shortly.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://28655]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (6)
As of 2024-04-23 11:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found