References


https://msdn.microsoft.com/ko-kr/library/7df7sf4x(v=vs.94).aspx

[자바스크립트] 동일한 단어를 문자열에서 찾기, Match() 함수


Sources


var src = "azcafAJAC";


var re = /[a-c]/;


var result = src.match(re);


// The entire match is in array element 0.

document.write(result[0] + "<br/>");


// Now try the same match with the global flag.

var reg = /[a-c]/g;

result = src.match(reg);



// The matches are in elements 0 through n.

for (var index = 0; index < result.length; index++)

{

    document.write ("submatch " + index + ": " +  result[index]);

    document.write("<br />");

}




Syntax


stringObj.match(rgExp) 


1. stringObj : 문자열

2. rgExp : 정규식 혹은 찾고자 할 문자열




Example


1. 

var str = 'red is impressive.'

str.match('red');


2.

var test  = 'love you. love me. love everything!'
var regExp = /love/gi;
test2 = test.match(regExp);


반응형

+ Recent posts