๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Javascript

์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ : ๋ฌธ์ž์—ด ๊ฒ€์ƒ‰ ๋ฉ”์„œ๋“œ : match()

by ์ฝ”ํŒŒ์นด 2022. 8. 22.
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

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

728x90

๋Œ“๊ธ€

๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค. ๐Ÿฆ™

CSS
๊ด‘๊ณ  ์ค€๋น„์ค‘