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

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

by _ํ† ๋งคํ†  2022. 8. 23.
728x90

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

์ด๋ฒˆ ์‹œ๊ฐ„์—๋Š” ๋ฌธ์ž์—ด ๋ฉ”์„œ๋“œ์ธ match()์— ๋Œ€ํ•ด ์•Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค! ๐Ÿ˜


#1. match( )

match() ๋ฉ”์„œ๋“œ๋Š” ๋ฌธ์ž์—ด์„ ๊ฒ€์ƒ‰ํ•˜๊ณ  ๋ฐฐ์—ด์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

! match( ) ์‚ฌ์šฉ ๋ฐฉ๋ฒ• !
"๋ฌธ์ž์—ด".math(๊ฒ€์ƒ‰๊ฐ’);
"๋ฌธ์ž์—ด".math(์ •๊ทœ์‹ ํ‘œํ˜„);

const str1 = "javascript reference";

const currentStr1 = str1.math("javascript");    // javascript
const currentStr2 = str1.math("reference");     // reference
const currentStr3 = str1.math("r");             // r
const currentStr4 = str1.math(/reference/);     // reference
const currentStr5 = str1.math(/Reference/);     // null
const currentStr6 = str1.math(/Reference/i);    // reference
const currentStr7 = str1.math(/r/g);            // ['r', 'r', 'r']
const currentStr8 = str1.math(/e/g);            // ['e', 'e', 'e', 'e']

! point ! ๋Œ€์†Œ๋ฌธ์ž๋ฅผ ๊ตฌ๋ถ„ํ•˜๋ฉฐ ๋ฌธ์ž์—ด์— ๊ฒ€์ƒ‰๊ฐ’์ด ์—†์„ ๊ฒฝ์šฐ null์ด ๋ฐ˜ํ™˜๋œ๋‹ค!

728x90

๋Œ“๊ธ€


Lucky Charms Rainbow
js
html
css