728x90
반응형
match()
match() 메서드는 문자열을 검색하고 검색값을 배열로 반환합니다.
match()
"문자열".match("검색값");
"문자열".match(정규식표현);
const str1 = "javascript reference";
const currentStr1 = str1.match("javascript"); //javascript
const currentStr2 = str1.match("reference"); //reference
const currentStr3 = str1.match("r"); //r
const currentStr4 = str1.match(/reference/); //reference
const currentStr5 = str1.match(/Reference/); //null
const currentStr6 = str1.match(/Reference/i); //reference
const currentStr7 = str1.match(/r/g); //['r', 'r', 'r']
const currentStr8 = str1.match(/e/g); //['e', 'e', 'e', 'e']
'JavaScript' 카테고리의 다른 글
함수의 유형 (3) | 2022.08.22 |
---|---|
charAt( ) (2) | 2022.08.22 |
search( ) (2) | 2022.08.22 |
toUpperCase( ) / toLowerCase( ) / trim( ) (1) | 2022.08.17 |
concat( ) / repeat( ) / includes( ) (2) | 2022.08.17 |
댓글