Shortcode to find and replace URL

Your shortcode function should look like this:

function replace_url_for_nonlogged( $atts, $content = "") {
  if ( is_user_logged_in () ) return $content;
  extract( shortcode_atts( array(
    'replace' => 'http://www.default_replace_url.com',
  ), $atts ) );
  $pattern = '/href=("|\')((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)("|\')/';
  return preg_replace($pattern, "href=\"$replace\"", $content);
}
add_shortcode( 'scode', 'replace_url_for_nonlogged' );

Then you can use the shortcode like this:

[scode]Lorem <a href="http://reservedurl.com">ipsum</a> dolor <a href="http://resersinglequoted.com">simet</a>.[/scode]

and the output became:

Lorem <a href="http://www.default_replace_url.com">ipsum</a> dolor <a href="http://www.default_replace_url.com">simet</a>.

the url replaced is setted as default in the replace_url_for_nonlogged function.

If you want you can pass the replacent url via shortcode att, e.g.

[scode replace="http://www.google.com"]Lorem <a href="http://reservedurl.com">ipsum</a> dolor <a href="http://resersinglequoted.com">simet</a>.[/scode]

and this time the output became:

Lorem <a href="http://www.google.com">ipsum</a> dolor <a href="http://www.google.com">simet</a>.

enter image description here