본문 바로가기
JAVASCRIPT

메서드 (match)

by 코빈_ 2022. 8. 22.

match()

문자열(정규식)을 검색하고, 위치 값(배열)을 반환한다.

    const str1 ="javascript reference"
    const currentStr1 = str1.match("javascipt");         // javascipt
    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 i는 소,대문자 구별x
    const currentStr7 = str1.match(/r/g);                    // ['r', 'r', 'r']
    const currentStr8 = str1.match(/e/g);                   // ['e', 'e', 'e', 'e']

'JAVASCRIPT' 카테고리의 다른 글

함수 유형  (5) 2022.08.22
메서드 (charAt)  (3) 2022.08.22
메서드 (search)  (3) 2022.08.22
메서드 (trim / trimStart / trimEnd)  (2) 2022.08.18
메서드 (includes)  (2) 2022.08.18

댓글


INFORMATION

javascript

css

html