jQuery urlInternal allows you to test whether any URL is internal or external, using an easily configurable RegExp. It can also test whether any URL is a fragment that will only change the location.hash, instead of navigating to a new page, even in IE6/7! Where would you use this? Here are a few basic examples, I'm sure you can come up with more:

Some common usage examples

// Open every external link in a new window.
$("a:urlExternal").attr( "target", "_blank" );

// Pass document query string through to all internal links and forms (see jQuery BBQ at
// http://benalman.com/projects/jquery-bbq-plugin/ for the query string methods).
$("a, form").urlInternal().querystring( $.deparam.querystring() );

// Add an onclick handler to all fragment links (see jQuery BBQ for the pushState and fragment
// methods). In most browsers, you can do $("a[href^=#]") but that won't always work in IE6/7!
// Either make your selector more robust, or use :urlFragment!
$("a:urlFragment").click(function(){
  var frag = $.param.fragment( $(this).attr( 'href' ) );
  $.bbq.pushState({ page: frag });
  return false;
});

Tests

// For each of the example spans (at the bottom), test the URL in the "data-url" attribute.
$.elemUrlAttr({ span: 'data-url' });

// In tests 1-3, .urlInternal and .urlExternal are tested for the item in each table row,
// using each of these values.
$.urlInternalHost( "www" ); // 1
$.urlInternalHost( "foo" ); // 2
$.urlInternalRegExp( /^(?:https?:)?\/\/(?:(?:www|foo)\.)?benalman.com\// ); // 3

// In test 4, .urlFragment is tested for the item in each table rom.

Results

relative links
element
./
../
?test=&a=1&a=2&b=boo
foo
foo#test-anchor
foo/bar.html?baz=123
bar.html?test=&a=1&a=2&b=boo
/foo/
/foo/bar.html?baz=123
/bar.html?test=&a=1&a=2&b=boo
foo#test-anchor
/foo#test-anchor
absolute links
element
//benalman.com/
//www.benalman.com/
//foo.benalman.com/
http://benalman.com/
http://benalman.com/foo/bar.html
http://benalman.com/bar.html?test=&a=1&a=2&b=boo
http://www.benalman.com/
http://www.benalman.com/foo/#test-anchor
http://foo.benalman.com/
http://foo.benalman.com/bar.html?test=&a=1&a=2&b=boo
https://foo.benalman.com/
https://benalman.com/
https://www.benalman.com/
http://bar.benalman.com/
http://benalman.com:81/
http://bar.benalman.com/#foo
http://benalman.com:81/#bar
http://google.com/
http://google.com/bar.html?test=&a=1&a=2&b=boo
fragment links
element
#test-anchor
./#test-anchor
../urlinternal/#test-anchor
absolute path to this page plus a fragment
/relative path to this page plus a fragment
non-navigating links
element
mailto:spam@benalman.com
javascript:alert('hello world')
ftp://ftp.example.com/foo/bar
irc://irc.example.com/foo/bar
arbitrary-scheme://example.com/foo/bar
arbitrary-scheme:example.com/foo/bar
form
element
<form action="?mode=test" method="post">
<form action="http://benalman.com/foo/?a=1&b=2" method="get">
<form action="http://www.benalman.com/foo/?a=1&b=2" method="get">
<form action="http://foo.benalman.com/bar/?a=1&b=2" method="get">
<form action="https://benalman.com/foo/?a=1&b=2" method="get">
<form action="http://google.com/search?q=ben+alman" method="get">
span (using HTML5 "data-url" attribute)
element
<span data-url="?mode=test">
<span data-url="http://benalman.com/foo/?a=1&b=2">
<span data-url="http://www.benalman.com/foo/?a=1&b=2">
<span data-url="http://foo.benalman.com/bar/?a=1&b=2">
<span data-url="https://benalman.com/foo/?a=1&b=2">
<span data-url="http://google.com/search?q=ben+alman">