The regularity problem of matching url query parameters

functions that match parameters in url in js on the Internet

function getQueryString(name){
            var reg = new RegExp("(^|&)"+name+"=([^&]*)(&|$)");
            var href = window.location.href
            var index = href.indexOf("?")
            var r = href.substr(index+1).match(reg);
            if(r != null)
            return unescape(r[2]);
            return null;
        }

I see the explanation that the first (^ | &) is ^ or & or none, (& | $) is & or $or none;
but I try to start with ^ and it won"t match.
so I understand that ^ here is the beginning and $is the end.
if so | & how to understand, or whether it is possible to write ^ (&), | meaningless. This returns null.
I finally tried ^ (| &) "+ name+" = (< sup id= "fnref-1" > 1 < / sup > *) (& |) $, and the returned result is consistent with the source code.
so | what is the effect, is there no or &?

< hr >
    < li id= "fn-1" > &

^ | & is the position that matches the beginning or the place where & appears


my understanding of existing knowledge is | means "or". It should be worth it twice. If it is not worth it, I guess it is an empty string or an empty string

.
 console.log(/|/.test("12313"));  //true

and what you write (^ | &) means either (^) , that is, an empty beginning, or & ,

console.log(/(^|&)/.test("12131"));  //true
console.log(/(^a|&)/.test("12131")); //false

you can refer to this article: https://codeshelper.com/a/11.

"
Menu