728x90
๋ฌธ์์ด ๊ฒ์ ๋ฉ์๋ : match()
match() ๋ฉ์๋๋ ๋ฌธ์์ด(์ ๊ท์ ํฌํจ)์ ๊ฒ์ํ๊ณ , ๋ฐฐ์ด๋ก ๋ฐํํฉ๋๋ค.
match() ๋ฉ์๋
1. "๋ฌธ์์ด".match("๊ฒ์๊ฐ")
const str1 = "javascript reference";
const currentStr1 = str1.match("javascript");
const currentStr2 = str1.match("reference");
const currentStr3 = str1.match("r");
๊ฒฐ๊ณผ๋ณด๊ธฐ
javascript
reference
r
reference
r
2. "๋ฌธ์์ด".match(์ ๊ท์ ํํ)
const str1 = "javascript reference";
const currentStr1 = str1.match(/reference/);
const currentStr2 = str1.match(/Reference/);
const currentStr3 = str1.match(/Reference/i);
const currentStr4 = str1.match(/r/g);
const currentStr5 = str1.match(/e/g);
๊ฒฐ๊ณผ๋ณด๊ธฐ
reference
null
reference
['r', 'r', 'r']
['e', 'e', 'e', 'e']
null
reference
['r', 'r', 'r']
['e', 'e', 'e', 'e']
728x90
'Javascript' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
์๋ฐ์คํฌ๋ฆฝํธ : ํจ์์ ์ ํ (11) | 2022.08.22 |
---|---|
์๋ฐ์คํฌ๋ฆฝํธ : ๋ฌธ์์ด ๊ฒ์ ๋ฉ์๋ : charAt() (10) | 2022.08.22 |
์๋ฐ์คํฌ๋ฆฝํธ : ๋ฌธ์์ด ๊ฒ์ ๋ฉ์๋ : search() (9) | 2022.08.22 |
์๋ฐ์คํฌ๋ฆฝํธ : ๋ฌธ์์ด ๊ฒ์ ๋ฉ์๋ : includes() (6) | 2022.08.17 |
์๋ฐ์คํฌ๋ฆฝํธ : ๋ฌธ์์ด ๋ณ๊ฒฝ ๋ฉ์๋ : padStart() / padEnd() (5) | 2022.08.17 |
๋๊ธ