본문 바로가기
JAVASCRIPT

JAVASCRIPT | 문자열 메서드 | match( )

by 코딩하자9 2022. 8. 22.
728x90

match( )에 대해 알아보자 !

String.prototype.match( );
match( ) 메서드는 문자열이 정규식과 매치되는 부분을 검색합니다.


construction(구문)

str.match("searching"/regexp)

searchString(찾을 문자열, 검색값) / regexp(정규식 표현)

문자열이 정규식과 일치한다면 일치하는 전체 문자열을 첫 번째 요소로 포함하는 "배열"을 반환합니다.
일치하는 것이 없으면 null이 반환됩니다.

# 예제를 통해 익혀봅시다.

const str1 = "javascript reference";

const currentstr1 = str1.match("javascript");
const currentstr2 = str1.match("reference");
const currentstr3 = str1.match("r");
const currentstr4 = str1.match(/reference/);
const currentstr5 = str1.match(/Reference/);
const currentstr6 = str1.match(/Reference/i);
const currentstr7 = str1.match(/r/g);
const currentstr8 = str1.match(/e/g);   
결과보기
['javascript']
['reference']
['r']
['reference']
null
null
['r', 'r', 'r']
['e', 'e', 'e', 'e']

댓글


It's cording time

코딩 여기서 정리하고 배워보자구 :9

광고 준비중입니다.