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.

"
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b35717-2bfc1.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b35717-2bfc1.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?