๋ฐ์ํ
๋ฌธ์์ด ๋ฉ์๋ : 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']
๋ฐ์ํ
'JavaScript' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[JavaScript] GSAP ์์๋ณด๊ธฐ (3) | 2022.08.29 |
---|---|
[JavaScript] ๋ฌธ์์ด ๋ฉ์๋ - charAt() (7) | 2022.08.22 |
[JavaScript] ๋ฌธ์์ด ๋ฉ์๋ - search() (6) | 2022.08.22 |
[JavaScript] ํจ์ ์ ํ ์์๋ณด๊ธฐ (6) | 2022.08.22 |
[JavaScript] ๋ฌธ์์ด ๋ฉ์๋ - includes() (4) | 2022.08.17 |
๋๊ธ