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

[JavaScript] ๋ฌธ์ž์—ด ๋ฉ”์„œ๋“œ - match()

by ์ฝ”๋”ฉ๊ณต์ฑ… 2022. 8. 22.
๋ฐ˜์‘ํ˜•

๋ฌธ์ž์—ด ๋ฉ”์„œ๋“œ : 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']
๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€


Reference Book

JavaScript
HTML
CSS
๊ด‘๊ณ  ์ค€๋น„์ค‘์ž…๋‹ˆ๋‹ค.