728x90
문자열 메서드 : match()
문자열 메서드를 활용하면 원하는 문자가 포함된 문자열을 찾을 수 있습니다.
> 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']
728x90
'Javascript' 카테고리의 다른 글
함수 유형 알아보기 (9) | 2022.08.22 |
---|---|
문자열 메서드 : charAt() / charCodeAt() (9) | 2022.08.22 |
문자열 메서드 : search() (7) | 2022.08.22 |
문자열 메서드 : includes() (6) | 2022.08.17 |
문자열 메서드 : padStart() / padEnd() (5) | 2022.08.17 |
댓글