in reply to Re: The "anchor" misnomer in regexes
in thread The "anchor" misnomer in regexes

It is easy to see that $string =~ /#(.*?)$/ could be processed as reverse $string =~ /^(.*?)#/ and it would then produce very different and perhaps more intuitive results.

Those aren't identical.

$string = "abc#def#ghi"; ($x) = $string =~ /#(.*?)$/; print "$x\n"; ($x) = reverse($string) =~ /^(.*?)#/; $x = reverse $x; print "$x\n"; ---- def#ghi ghi
You're still thinking of $ as a starting point versus simply being a zero-width assertion. /#([^#]*)$/ is the one that reverses to /^(.*?)#/. The original regex /#(.*?)$/ is more clearly written as /#(.*)$/. Because you don't have any non-zero-width assertions between the .*? and the $, the non-greedy modifier doesn't actually change any behavior. The reverse of the original is /^(.*)#/ - explicitly greedy.

My criteria for good software:
  1. Does it work?
  2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?

Replies are listed 'Best First'.
Re^3: The "anchor" misnomer in regexes
by eric256 (Parson) on Dec 18, 2005 at 01:56 UTC

    I didn't say they were identical, and i can't "still" be thinking of them in any way because its my first post. Reading "How does your idea of anchors hold when there are more than one?" I meant to say that the rest of the post would be regarding how the OP was thinking anchors WOULD be, not how they are. My intention was to show that while that view might make sense with the simple single ended cases, more complex cases make it apparent that the current meaning of anchor is realy the one of least surprise and easiest implementation.


    ___________
    Eric Hodges $_='y==QAe=e?y==QG@>@?iy==QVq?f?=a@iG?=QQ=Q?9'; s/(.)/ord($1)-50/eigs;tr/6123457/- \/|\\\_\n/;print;