var regExp1 = /(t\w+e)/g; var str = 'tims tar time the'; var matchs; while ((matchs = regExp1.exec(str))) { // 매칭된 문자열을 하나씩 반환 시킨다. alert(matchs[0]); } // 매칭된 문자열에 전체에 span 태그를 Wrapping 시켜 반환한다. alert(str.replace(regExp1, '<span style="color:red">$1</span>'));