I stumbled across this article which was talking about AJAX and jQuery and I reached this line
hash = hash.replace(/^.*#/, '');
where hash is in the form #page1,#page2 etc…
Now what I don’t understand is why
hash = hash.replace(/^#/, '');
will not suffice. From the Mozilla Docs,
^ Matches beginning of input. If the multiline flag is set to true, also matches immediately after a line break character.
So with this caret alone I should be able to match the hash value, what is the author trying to do ?
Your proposed regex will match only a hash symbol right at the beginning of the string, and nowhere else. The first regex you posted will match everything up to the the first hash symbol in the string.