RegExp#exec
and String#match
JS-D0071var clear="img/clear.gif" //path to clear.gif
2
3pngfix=function(){var els=document.getElementsByTagName('*');var ip=/\.png/i;var i=els.length;while(i-- >0){var el=els[i];var es=el.style;if(el.src&&el.src.match(ip)&&!es.filter){es.height=el.height;es.width=el.width;es.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+el.src+"',sizingMethod='crop')";el.src=clear;}else{var elb=el.currentStyle.backgroundImage;if(elb.match(ip)){var path=elb.split('"');var rep=(el.currentStyle.backgroundRepeat=='no-repeat')?'crop':'scale';es.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+path[1]+"',sizingMethod='"+rep+"')";es.height=el.clientHeight+'px';es.backgroundImage='none';var elkids=el.getElementsByTagName('*');if (elkids){var j=elkids.length;if(el.currentStyle.position!="absolute")es.position='static';while (j-- >0)if(!elkids[j].style.position)elkids[j].style.position="relative";}}}}}4window.attachEvent('onload',pngfix);
116
117 tippoint.style.backgroundImage = "none";
118 }
119 if (tipcap.currentStyle.backgroundImage.match(/\.png/gi)) {120 var tipC = tipcap.innerHTML;
121
122 tipcap.id = 'unitipC';
95 PointHeight = document.getElementById('unitippoint').offsetHeight;
96
97 if (typeof pngfix=="function") { // if IE, rebuilds wraps unitippoint and unitipcap in outer div
98 if (tippoint.currentStyle.backgroundImage.match(/\.png/gi)) { 99 var tipP = tippoint.innerHTML;
100
101 tippoint.id = 'unitipP'; // switch unitippoint to outer div
RegExp#exec
and String#match
should only be used when we need to use the parts of a string that match a specific pattern:
const matches = /[a-zA-Z0-9]+/.exec(string)
for (const match of matches) {
processMatch(match)
}
If you only want to know whether a string matches a particular pattern, RegExp#test
is a faster alternative.
const matches = str.match(/[a-zA-Z0-9]/) ? process(str) : process("default-str");
const strMatchesPattern = !!str.match(/regex/)
const regexp = new RegExp("[a-zA-Z0-9]*")
if (regexp.exec(myString)) {
// ...
}
const matches = '/hasTheMagic/'.test(str) ? process(str) : process("default-str");
const strMatchesPattern = /regex/.test(str)
const regexp = new RegExp("[a-zA-Z0-9]*")
if (regexp.test(myString)) {
// ...
}