Why (?! ^) Equivalent to (? <! ^)?
Some time ago I answered this question on SO, but I still do not understand why my answer worked.
For some reason, a negative result for the beginning of a line behaves the same as a negative lookbehind.
For example, in PHP
preg_replace("/(?!^)12/", "ab", "12345"); // 12345
preg_replace("/(?<!^)12/", "ab", "12345"); // 12345
preg_replace("/(?!1)23/", "ab", "12345"); // 1ab45
preg_replace("/(?<!1)23/", "ab", "12345"); // 12345
I know that this is not the most useful question that has ever been asked, but it has already imposed on me a couple of weeks.
+5