/**
* TiM's Regex Tester
*
* Some basic regex examples that can be used
* by default.
*
* Powered by jQuery - http://www.jquery.com/
**/

var regex_examples = [ { name: 'ex_match_ip', blurb: 'Match an IP address', regex: '/([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})/' },
						{ name: 'ex_match_html', blurb: 'Match HTML tags', regex: '/<([a-z]+)[^>]+?>(.*?)<\\/\\1>/i' },
						{ name: 'ex_match_email', blurb: 'Match email address', regex: '/[a-z0-9._-]+@[a-z0-9_-]+\\.[a-z.]+/i' },
						{ name: 'ex_match_cc', blurb: 'Match credit card number', regex: '/([0-9]{4})-([0-9]{4})-([0-9]{4})-([0-9]{4})/' },
						{ name: 'ex_match_dec', blurb: 'Match a decimal number', regex: '/([0-9]+)\\.([0-9]+)/' }
					];

function PopulateExampleList() 
{
	el = $('#regex_examples');
	
	for( i=0; i<regex_examples.length; i++ )
	{
		ex = regex_examples[i];
		el.append( $('<option></option>').val(ex.name).html(ex.blurb) );
	}
}

function AddRegexExample()
{
	target = $('#regex_field');
	list = $('#regex_examples');

	if( list.val() == 'none' )
		return;

	//loop through list of examples and match out
	//an entry by value
	for( i=0; i<regex_examples.length; i++ )
	{
		ex = regex_examples[i];
		if( ex.name == list.val() )
			break;
	}

	//a result was found
	if( i<regex_examples.length )
		target.append( regex_examples[i].regex );
}
					  
