function doMatch(matchString) 
{
	//alert('matchString='+matchString)
	matchString=matchString.replace(/-/g,"");
	var re = new RegExp('(\\d{13})|(\\d{9}[\\dXx])|([\\d\\- ]{11}[\\-| ][\\dXx])');
	//var re = new RegExp('(\\d{13})')
	var m;
	var index = 0;
	var s='';
	var isbn = new Array();
	var i=0;
	var separator='';
	var fails='';
	m = re.exec(matchString);
	
	while(m)
    {
        //alert('m[0].length='+ m[0].length)
		//alert('m[0]='+ m[0])
		isbn[i]=m[0];
		index+=m.index+m[0].length;
		m = re.exec(matchString.substr(index));
		//alert('after processing='+m)
		i++;
	}
    //alert('isbn='+isbn)
	//run mathematical check to weed out dodgy isbns
	for(i=0; i<isbn.length; i++)
    {
        var numsOnly='';
		var checkTotal=0;
		//alert('isbn[i]'+isbn[i])
        for(var ii=0; ii<isbn[i].length; ii++){
                if(parseInt(isbn[i].substr(ii,1))>=0 || isbn[i].substr(ii,1)=='x' || isbn[i].substr(ii,1)=='X'){
                    if (isbn[i].substr(ii,1)=='x' || isbn[i].substr(ii,1)=='X'){
                        numsOnly+= 10;
                    }
                    else {
                        numsOnly+=parseInt(isbn[i].substr(ii,1)).toString();
                    }
                }
            }
		if(isbn[i].length < 11)
		{
            
            for(ii=0; ii<9; ii++){		
                if (isbn[i].substr(ii,1)=='x' || isbn[i].substr(ii,1)=='X'){
                    checkTotal+=parseInt(10 * (10-ii));
                }
                else {
                    checkTotal+=parseInt(numsOnly.substr(ii, 1)) * (10-ii);
                }
            }
            if (isbn[i].substr(ii,1)=='x' || isbn[i].substr(ii,1)=='X'){
                checkTotal+= 10;
            }
            else 
            {
                checkTotal+=parseInt(numsOnly.substr(9, 1));
            }
            if(checkTotal%11!=0){
                if(numsOnly.length==10 || numsOnly.length==11)
                    if (isbn[i].substr(ii,1)=='x' || isbn[i].substr(ii,1)=='X')
                    {	fails += isbn[i]+'X' + '  ';	}
                    else {	fails += isbn[i] + '  ';	}
                isbn[i]='';
            }
        }	//alert(isbn[i])
        else{
            if(isbn[i].length <= 13) 
            {
		var grpA =0;
                var grpB=0;
                var chkDigit=0;


                for(ii=0; ii<13; ii++)
                {		
                    if (ii%2 ==0)
                    {
                        grpA+=parseInt(numsOnly.substr(ii, 1));
                    }
                    else{
                        grpB+=parseInt(numsOnly.substr(ii, 1));
                    }
                } //End of FOR loop
		grpB=grpB * 3;
                chkDigit=(grpA + grpB)%10;
		
		if (chkDigit != 0)
                {
                    chkDigit=(10 - chkDigit);
                }
		if (numsOnly.substr(ii,1) !=chkDigit) {
                    fails += isbn[i] + '  '	;
					 isbn[i]='';
                }

            } //Till here ISBN13 validation
        }
    }	
    for(i=0; i<isbn.length; i++){
        if(isbn[i]!='')
            s+= separator + isbn[i];
        separator='\n'
    }
    //alert('s='+s)	
    if(fails.length!=''){
        alert('The following isbnBNs were deemed to be invalid: ' + fails);
    }
    return s;
}
