JAVASCRIPT

메서드 (match)

코빈_ 2022. 8. 22. 13:35

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']