Use Regex to insert jQuery querystring before a url anchor
Rather than writing your own solution you could just a solution that's already tried and tested, like the parse_url() function on phpjs.

It works exactly the same way as PHP's parse_url() so you can use it to extract all elements of the url, alter what you need, then build it up again.

For example calling the function like this:

var components = parse_url('http://username:password@hostname/path?arg=value#anchor');


Will yield the following result:

{
  scheme: 'http', 
  host: 'hostname', 
  user: 'username', 
  pass: 'password', 
  path: '/path', 
  query: 'arg=value', 
  fragment: 'anchor'
}


From there it'll be easy to manipulate the values you're interested in and build up a new URL, without having to resort to a another regex.

Basic example:

$('a[href^="/example/"]').each(function(index, element) {
  var components = parse_url($(this).attr('href'));

  var newUrl = components.scheme + '://' + components.hostname + '/' + components.path + '?parent=' + Drupal.settings.nodeinfo.nid + '#' + components.anchor;

  $(this).attr('href', newUrl);
});