// 6. // 매칭된 영역을 배열(전체 문자열, $1, $2)로 반환합니다. alert('tims the test jsk'.match(/(t\w*s)\s(t\w*e)/)[0]); alert('tims the test jsk'.match(/(t\w*s)\s(t\w*e)/)[1]); alert('tims the test jsk'.match(/(t\w*s)\s(t\w*e)/)[2]); // 7. // 매칭 유/무를 반환합니다. alert(/^\s+|\s+$/.test(' mohwa project ')); // 8. // 매칭된 문자열을 치환합니다. alert(' mohwa project '.replace(/^\s+|\s+$/g, '^')); // 매칭된 첫 문자열 index를 반환합니다. alert(' mohwa project '.search(/mohwa/)); // 1 alert(' mohwa project '.search(/project/)); // 7 // 9. // 매칭된 영역이 없을 시 null을 반환하고, 일치하는 부분이 있다면 배열을 반환합니다. // 매칭된 index alert(/^\d+|\d+$/g.exec('1mohwa project1').index); // 전체 문자열 alert(/^\d+|\d+$/g.exec('1mohwa project1').input); // 매칭된 값 index 접근 alert(/^\d+|\d+$/g.exec('1mohwa project1')[0]); // 매칭된 모든 문자열 치환 alert('1mohwa project1'.replace(/^\d+|\d+$/g, '2')); // 10. alert(' mohwa project '.replace(/^\s+|\s+$/, '')); // 11. alert('<html></html>'.replace(/html/g, '')); alert('<html><head><title>head Title</titel><body></body></html>'.replace(/</g, '<').replace(/>/g, '>')); // 12. alert(/:(.*)\./g.exec('jsk: mohwa project.')[0]); alert(/:(.*)\./g.exec('jsk: mohwa project.')[1]);