๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
์นดํ…Œ๊ณ ๋ฆฌ ์—†์Œ

Code States 53์ผ์ฐจ - ์ •๊ทœํ‘œํ˜„์‹

by ์ฃ ๋ฅด๋ ์— 2021. 10. 13.

๐Ÿ˜… ์•Œ๊ณ ๋ฆฌ์ฆ˜์— ์žˆ๋˜ ์ •๊ทœํ‘œํ˜„์‹์„ ์ •๋ฆฌ ๋ชปํ•ด์„œ ์ •๋ฆฌํ•ด๋ณด๋„๋ก ํ•˜์ž.


๋Œ€๋ถ€๋ถ„์˜ ํšŒ์›๊ฐ€์ž…์ด ํ•„์š”ํ•œ ์„œ๋น„์Šค๋Š” ๋น„๋ฐ€๋ฒˆํ˜ธ ์„ค์ • ์‹œ ํŠน์ • ์กฐ๊ฑด์— ๋งž์ถ”์–ด ์ž…๋ ฅํ•˜๋ผ๊ณ  ์š”๊ตฌํ•œ๋‹ค. ๋น„๋ฐ€๋ฒˆํ˜ธ ์„ค์ •์— ํŠน์ • ์กฐ๊ฑด์„ ์š”๊ตฌํ•˜๋Š” ๊ฒƒ์€ ๋ณด์•ˆ ๋•Œ๋ฌธ์ด๋‹ค. ๊ทธ๋Ÿฌ๋ฉด ํ•ด๋‹น ์„œ๋น„์Šค์˜ ๊ด€๋ฆฌ์ž๋Š” ์–ด๋–ป๊ฒŒ ๋น„๋ฐ€๋ฒˆํ˜ธ์˜ ์ž…๋ ฅ ์กฐ๊ฑด์„ ์„ค์ •ํ•˜๊ณ  ๊ด€๋ฆฌํ•  ๋•Œ ๊ฐ„๋‹จํ•˜๊ฒŒ ํ•˜๋Š” ๋ฐฉ๋ฒ•์œผ๋กœ ์ •๊ทœํ‘œํ˜„์‹์ด ์žˆ๋‹ค.

 

์ •๊ทœํ‘œํ˜„์‹์„ ํ•œ ๋ฌธ์žฅ์œผ๋กœ ์ •์˜ํ•˜๋ฉด ๋ฌธ์ž์—ด์—์„œ ํŠน์ •ํ•œ ๋ฌธ์ž๋ฅผ ์ฐพ์•„๋‚ด๋Š” ๋„๊ตฌ์ด๋‹ค. ์ •๊ทœํ‘œํ˜„์‹์„ ์ด์šฉํ•˜๋ฉด ์ˆ˜์‹ญ ์ค„์ด ํ•„์š”ํ•œ ์ฝ”๋”ฉ ์ž‘์—…์„ ๊ฐ„๋‹จํ•˜๊ฒŒ ํ•œ๋‘ ์ค„๋กœ ๋๋‚ผ ์ˆ˜ ์žˆ๋‹ค. ์ •๊ทœํ‘œํ˜„์‹์€ ํŠน์ •ํ•œ ๊ทœ์น™์„ ๊ฐ–๋Š” ๋ฌธ์ž์—ด๋กœ ์ด๋ฃจ์–ด์ง„ ํ‘œํ˜„์‹์ด๋ฉฐ, ์ •๊ทœํ‘œํ˜„์‹์—์„œ ํŠน์ˆ˜ ๋ฌธ์ž๋Š” ๊ฐ๊ฐ์˜ ๊ณ ์œ ํ•œ ๊ทœ์น™์„ ๊ฐ–๊ณ  ์žˆ๋‹ค. ์ด๋Ÿฌํ•œ ๊ทœ์น™๋“ค์„ ์กฐํ•ฉํ•˜์—ฌ ์›ํ•˜๋Š” ํŒจํ„ด์„ ๋งŒ๋“ค๊ณ , ํŠน์ • ๋ฌธ์ž์—ด์—์„œ ํ•ด๋‹น ํŒจํ„ด๊ณผ ๋Œ€์‘ํ•˜๋Š” ๋ฌธ์ž๋ฅผ ์ฐพ์„ ์ˆ˜ ์žˆ๋‹ค. 

 

์•„๋ž˜์˜ ์ฝ”๋“œ๋Š” ์‚ฌ์šฉ์ž๊ฐ€ ์ž…๋ ฅํ•œ ์ด๋ฉ”์ผ์ด๋‚˜ ํœด๋Œ€์ „ํ™” ๋ฒˆํ˜ธ๊ฐ€ ์œ ใ…›ํ•œ์ง€ ํ™•์ธํ•˜๊ณ ์ž ํ•  ๋•Œ ์‚ฌ์šฉํ•˜๋Š” ์ •๊ทœํ‘œํ˜„์‹์ด๋‹ค. ์ •๊ทœํ‘œํ˜„์‹์„ ์‚ฌ์šฉํ•œ๋‹ค๋ฉด, ํ•œ ์ค„์˜ ์ฝ”๋“œ๋งŒ์œผ๋กœ ์ด๋ฉ”์ผ์ด๋‚˜ ํœด๋Œ€์ „ํ™” ๋ฒˆํ˜ธ์˜ ์œ ํšจ์„ฑ์„ ๊ฒ€์‚ฌํ•  ์ˆ˜ ์žˆ์ง€๋งŒ, ๋งŒ์•ฝ ๊ทธ๋ ‡์ง€ ์•Š์•˜๋‹ค๋ฉด ๊ฐ™์€ ๊ฒฐ๊ณผ๋ฅผ ์–ป๊ธฐ ์œ„ํ•ด์„œ๋Š” ๊ต‰์žฅํžˆ ๊ธด ์ฝ”๋“œ๊ฐ€ ํ•„์š”ํ–ˆ์„ ๊ฒƒ์ด๋‹ค.

์ด๋ฉ”์ผ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ

let regExp = /^[0-9a-zA-Z]([-_.]?[0-9a-zA-Z])*@[0-9a-zA-Z]([-_.]?[0-9a-zA-Z])*.[a-zA-Z]{2,3}$/i;

ํœด๋Œ€์ „ํ™” ๋ฒˆํ˜ธ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ

let regExp = /^01([0|1|6|7|8|9]?)-?([0-9]{3,4})-?([0-9]{4})$/;

์ •๊ทœํ‘œํ˜„์‹ ์‚ฌ์šฉํ•˜๊ธฐ

์ •๊ทœํ‘œํ˜„์‹์€ ๋‘ ๊ฐ€์ง€ ๋ฐฉ๋ฒ•์œผ๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

๋ฆฌํ„ฐ๋Ÿด ํŒจํ„ด

์ •๊ทœํ‘œํ˜„์‹ ๊ทœ์น™์„ ์Šฌ๋ž˜์‹œ(/)๋กœ ๊ฐ์‹ธ ์‚ฌ์šฉํ•œ๋‹ค. ์Šฌ๋ž˜์‹œ ์•ˆ์— ๋“ค์–ด์˜จ ๋ฌธ์ž์—ด์ด ์ฐพ๊ณ ์ž ํ•˜๋Š” ๋ฌธ์ž์—ด์ด๋ฉฐ, ์ปดํ“จํ„ฐ์—๊ฒŒ '์Šฌ๋ž˜์‹œ ์‚ฌ์ด์— ์žˆ๋Š” ๋ฌธ์ž์—ด์„ ์ฐพ๊ณ  ์‹ถ๋‹ค'๋ผ๊ณ  ๋ช…๋ น์„ ๋‚ด๋ฆฌ๋Š” ๊ฒƒ์ด๋‹ค.

let pattern = /c/;

์ƒ์„ฑ์ž ํ•จ์ˆ˜ ํ˜ธ์ถœ ํŒจํ„ด

let pattern = new RegExp('c');

์ •๊ทœํ‘œํ˜„์‹ ๋‚ด์žฅ ๋ฉ”์†Œ๋“œ

JavaScript์—์„œ ์ •๊ทœํ‘œํ˜„์‹์€ ๊ฐ์ฒด๋กœ์„œ ๋‚ด์žฅ ๋ฉ”์†Œ๋“œ๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ์œผ๋ฉฐ, String ๊ฐ์ฒด์—์„œ๋„ ์ •๊ทœํ‘œํ˜„์‹์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ๋‚ด์žฅ ๋ฉ”์†Œ๋“œ๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๋‹ค. ๋‚ด์žฅ ๋ฉ”์†Œ๋“œ๋ฅผ ์ด์šฉํ•˜๋ฉด ์–ด๋–ค ๋ฌธ์ž์—ด ์•ˆ์— ์›ํ•˜๋Š” ์ •๋ณด๋ฅผ ์ฐพ๊ฑฐ๋‚˜ ํŠน์ • ํŒจํ„ด์— ๋Œ€์‘ํ•˜๋Š” ๋ฌธ์ž์—ด์„ ๊ฒ€์ƒ‰, ์ถ”์ถœ, ๋‹ค๋ฅธ ๋ฌธ์ž์—ด๋กœ ์น˜ํ™˜ํ•  ์ˆ˜ ์žˆ๋‹ค.

RegExp ๊ฐ์ฒด์˜ ๋ฉ”์†Œ๋“œ

exec()

exec๋Š” execution์˜ ์ค„์ž„๋ง๋กœ, ์›ํ•˜๋Š” ์ •๋ณด๋ฅผ ๋ฝ‘์•„๋‚ด๊ณ  ํ•  ๋•Œ ์‚ฌ์šฉํ•œ๋‹ค. ๊ฒ€์ƒ‰์˜ ๋Œ€์ƒ์ด ์ฐพ๊ณ ์ž ํ•˜๋Š” ๋ฌธ์ž์—ด์— ๋Œ€ํ•œ ์ •๋ณด๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๋‹ค๋ฉด ์ด๋ฅผ ๋ฐฐ์—ด๋กœ ๋ฐ˜ํ™˜ํ•˜๋ฉฐ, ์ฐพ๋Š” ๋ฌธ์ž์—ด์ด ์—†๋‹ค๋ฉด null์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค.

let pattern = /c/;
pattern.exec('codestates);
// -> ['c']

test()

์ฐพ๊ณ ์ž ํ•˜๋Š” ๋ฌธ์ž์—ด์ด ๋Œ€์ƒ ์•ˆ์— ์žˆ๋Š”์ง€์˜ ์—ฌ๋ถ€๋ฅผ boolean์œผ๋กœ ๋ฆฌํ„ดํ•œ๋‹ค.

let pattern = /c/;
pattern.test('codestates');
// -> true

String ๊ฐ์ฒด์˜ ๋ฉ”์†Œ๋“œ

match()

RegExp.exec()์™€ ๋น„์Šทํ•œ ๊ธฐ๋Šฅ์„ ํ•˜๋ฉฐ, ์ •๊ทœํ‘œํ˜„์‹์„ ์ธ์ž๋กœ ๋ฐ›์•„ ์ฃผ์–ด์ง„ ๋ฌธ์ž์—ด๊ณผ ์ผ์น˜๋œ ๊ฒฐ๊ณผ๋ฅผ ๋ฐฐ์—ด๋กœ ๋ฐ˜ํ™˜ํ•œ๋‹ค. ์ผ์น˜๋˜๋Š” ๊ฒฐ๊ณผ๊ฐ€ ์—†์œผ๋ฉด null์„ ๋ฆฌํ„ดํ•œ๋‹ค.

let pattern = /c/;
let str = 'codestates';
str.match(pattern);
// -> ['c']

replace()

'๊ฒ€์ƒ‰ ํ›„ ๋ฐ”๊พธ๊ธฐ'๋ฅผ ์ˆ˜ํ–‰ํ•œ๋‹ค. ์ฒซ ๋ฒˆ์งธ ์ธ์ž๋กœ๋Š” ์ •๊ทœํ‘œํ˜„์‹์„ ๋ฐ›๊ณ , ๋‘ ๋ฒˆ์งธ ์ธ์ž๋กœ๋Š” ์น˜ํ™˜ํ•˜๋ ค๋Š” ๋ฌธ์ž์—ด์„ ๋ฐ›๋Š”๋‹ค. ๋ฌธ์ž์—ด์—์„œ ์ฐพ๊ณ ์ž ํ•˜๋Š” ๋Œ€์ƒ์„ ๊ฒ€์ƒ‰ํ•ด์„œ ์ด๋ฅผ ์น˜ํ™˜ํ•˜๋ ค๋Š” ๋ฌธ์ž์—ด๋กœ ๋ณ€๊ฒฝ ํ›„ ๋ณ€๊ฒฝ๋œ ๊ฐ’์„ ๋ฆฌํ„ดํ•œ๋‹ค.

let pattern = /c/;
let str = 'codestates';
str.replace(pattern, 'C');
// -> 'Codestates'

split()

์ฃผ์–ด์ง„ ์ธ์ž๋ฅผ ๊ตฌ๋ถ„์ž๋กœ ์‚ผ์•„, ๋ฌธ์ž์—ด์„ ๋ถ€๋ถ„ ๋ฌธ์ž์—ด๋กœ ๋‚˜๋ˆ„์–ด ๊ทธ ๊ฒฐ๊ณผ๋ฅผ ๋ฐฐ์—ด๋กœ ๋ฐ˜ํ™˜ํ•œ๋‹ค.

'123,456,789'.split(',') // ['123', '456', '789']
'12304560789'.split('0') // ['123', '456', '789']

search()

์ •๊ทœํ‘œํ˜„์‹์„ ์ธ์ž๋กœ ๋ฐ›์•„ ๊ฐ€์žฅ ์ฒ˜์Œ ๋งค์นญ๋˜๋Š” ๋ถ€๋ถ„ ๋ฌธ์ž์—ด์˜ ์œ„์น˜๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค. ๋งค์นญ๋˜๋Š” ๋ฌธ์ž์—ด์ด ์—†์œผ๋ฉด -1์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค.

"JavaScript".search(/script/); // -1 ๋Œ€์†Œ๋ฌธ์ž๋ฅผ ๊ตฌ๋ถ„ํ•ฉ๋‹ˆ๋‹ค
"JavaScript".search(/Script/); // 4
"codestates".search(/ode/); // 1

flag

์ •๊ทœํ‘œํ˜„์‹์€ ํ”Œ๋ž˜๊ทธ๋ฅผ ์„ค์ •ํ•ด ์ค„ ์ˆ˜ ์žˆ๊ณ , ํ”Œ๋ž˜๊ทธ๋Š” ์ถ”๊ฐ€์ ์ธ ๊ฒ€์ƒ‰ ์˜ต์…˜์˜ ์—ญํ• ์„ ํ•ด ์ค€๋‹ค. ์ด ํ”Œ๋ž˜๊ทธ๋“ค์€ ๊ฐ๊ฐ ํ˜น์€ ํ•จ๊ป˜ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ๋ชจ๋‘ ๊ฐ€๋Šฅํ•˜๊ณ , ์ˆœ์„œ์— ๊ตฌ๋ถ„์ด ์—†๋‹ค.

i

i๋ฅผ ๋ถ™์ด๋ฉด ๋Œ€์†Œ๋ฌธ์ž๋ฅผ ๊ตฌ๋ถ„ํ•˜์ง€ ์•Š๋Š”๋‹ค.

let withi = /c/i;
let withouti = /c/;
"Codestates".match(withi); // ['C']
"Codestates".match(withouti); // null

g

global์˜ ์•ฝ์ž๋กœ, g๋ฅผ ๋ถ™์ด๋ฉด ๊ฒ€์ƒ‰๋œ ๋ชจ๋“  ๊ฒฐ๊ณผ๋ฅผ ๋ฆฌํ„ดํ•œ๋‹ค.

let withg = /c/g;
let withoutg = /c/;
"coolcodestates".match(withg); // ['c', 'c']
"coolcodestates".match(withoutg); // ['c'] g ๊ฐ€ ์—†์œผ๋ฉด ์ฒซ ๋ฒˆ์งธ ๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ๋งŒ ๋ฐ˜ํ™˜ํ•œ๋‹ค.

m

m์„ ๋ถ™์ด๋ฉด ๋‹ค์ค‘ํ–‰์„ ๊ฒ€์ƒ‰ํ•œ๋‹ค.

let str = `1st : cool
2nd : code
3rd : states`;
str.match(/c/gm)
// 3๊ฐœ์˜ ํ–‰์„ ๊ฒ€์ƒ‰ํ•˜์—ฌ ๋ชจ๋“  c ๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค.
// ['c', 'c']
str.match(/c/m)
// m์€ ๋‹ค์ค‘ํ–‰์„ ๊ฒ€์ƒ‰ํ•˜๊ฒŒ ํ•ด ์ฃผ์ง€๋งŒ, g ๋ฅผ ๋นผ๊ณ  ๊ฒ€์ƒ‰ํ•˜๋ฉด ๊ฒ€์ƒ‰ ๋Œ€์ƒ์„ ์ฐพ๋Š” ์ˆœ๊ฐ„ ๊ฒ€์ƒ‰์„ ๋ฉˆ์ถ”๊ธฐ ๋•Œ๋ฌธ์—
// ์ฒซ ํ–‰์˜ ['c'] ๋งŒ ๋ฆฌํ„ดํ•œ๋‹ค.

์ •๊ทœ์‹ํŒจํ„ด(ํ‘œํ˜„์‹)

์ •๊ทœํ‘œํ˜„์‹์— ๋‹ค์–‘ํ•œ ํŠน์ˆ˜๊ธฐํ˜ธ๋ฅผ ํ•จ๊ป˜ ์‚ฌ์šฉํ•˜๋ฉด ๋ฌธ์ž์—ด์„ ๋‹ค๋ฃฐ ๋•Œ์— ๋” ๋งŽ์€ ์˜ต์…˜์„ ์„ค์ •ํ•  ์ˆ˜ ์žˆ๋‹ค.

์ •๊ทœ์‹ ํŒจํ„ด ์„ค๋ช…
^ ์ค„(Line)์˜ ์‹œ์ž‘์—์„œ ์ผ์น˜ /^abc/
$ ์ค„(Line)์˜ ๋์—์„œ ์ผ์น˜ /xyz$/
. (ํŠน์ˆ˜๊ธฐํ˜ธ, ๋„์–ด์“ฐ๊ธฐ๋ฅผ ํฌํ•จํ•œ) ์ž„์˜์˜ ํ•œ ๋ฌธ์ž
a|b a or b์™€ ์ผ์น˜, ์ธ๋ฑ์Šค๊ฐ€ ์ž‘์€ ๊ฒƒ์„ ์šฐ์„  ๋ฐ˜ํ™˜
* 0ํšŒ ์ด์ƒ ์—ฐ์†์œผ๋กœ ๋ฐ˜๋ณต๋˜๋Š” ๋ฌธ์ž์™€ ๊ฐ€๋Šฅํ•œ ๋งŽ์ด ์ผ์น˜. {0,}์™€ ๋™์ผ
*? 0ํšŒ ์ด์ƒ ์—ฐ์†์œผ๋กœ ๋ฐ˜๋ณต๋˜๋Š” ๋ฌธ์ž์™€ ๊ฐ€๋Šฅํ•œ ์ ๊ฒŒ ์ผ์น˜. {0,}์™€ ๋™์ผ
+ 1ํšŒ ์ด์ƒ ์—ฐ์†์œผ๋กœ ๋ฐ˜๋ณต๋˜๋Š” ๋ฌธ์ž์™€ ๊ฐ€๋Šฅํ•œ ๋งŽ์ด ์ผ์น˜. {1,}์™€ ๋™์ผ
+? 1ํšŒ ์ด์ƒ ์—ฐ์†์œผ๋กœ ๋ฐ˜๋ณต๋˜๋Š” ๋ฌธ์ž์™€ ๊ฐ€๋Šฅํ•œ ์ ๊ฒŒ ์ผ์น˜. {0}์™€ ๋™์ผ
{3} ์ˆซ์ž 3๊ฐœ ์—ฐ์† ์ผ์น˜
{3,} 3๊ฐœ ์ด์ƒ ์—ฐ์† ์ผ์น˜
{3, 5} 3๊ฐœ ์ด์ƒ 5๊ฐœ ์ดํ•˜ ์—ฐ์† ์ผ์น˜
() ๊ฐญ์ณ(capture)ํ•  ๊ทธ๋ฃน
[a-z] a๋ถ€ํ„ฐ z ์‚ฌ์ด์˜ ๋ฌธ์ž ๊ตฌ๊ฐ„์— ์ผ์น˜(์˜์–ด ์†Œ๋ฌธ์ž)
[A-Z] A๋ถ€ํ„ฐ Z ์‚ฌ์ด์˜ ๋ฌธ์ž ๊ตฌ๊ฐ„์— ์ผ์น˜(์˜์–ด ๋Œ€๋ถ„์ž)
[0-9] 0๋ถ€ํ„ฐ 9 ์‚ฌ์ด์˜ ๋ฌธ์ž ๊ตฌ๊ฐ„์— ์ผ์น˜(์ˆซ์ž)
\(์—ญ์Šฌ๋ž˜์‰ฌ) escape ๋ฌธ์ž. ํŠน์ˆ˜ ๊ธฐํ˜ธ ์•ž์— \๋ฅผ ๋ถ™์ด๋ฉด ์ •๊ทœ์‹ ํŒจํ„ด์ด ์•„๋‹Œ, ๊ธฐํ˜ธ ์ž์ฒด๋กœ ์ธ์‹
\d ์ˆซ์ž๋ฅผ ๊ฒ€์ƒ‰ํ•จ. /[0-9]/์™€ ๋™์ผ
\D ์ˆซ์ž๊ฐ€ ์•„๋‹Œ ๋ฌธ์ž๋ฅผ ๊ฒ€์ƒ‰ํ•จ. /[^0-9]/์™€ ๋™์ผ
\w ์˜์–ด๋Œ€์†Œ๋ฌธ์ž, ์ˆซ์ž, (underscore)๋ฅผ ๊ฒ€์ƒ‰ํ•จ. /[A-Za-z0-9]/์™€ ๋™์ผ
\W ์˜์–ด ๋Œ€์†Œ๋ฌธ์ž, ์ˆซ์ž, (underscore)๊ฐ€ ์•„๋‹Œ ๋ฌธ์ž๋ฅผ ๊ฒ€์ƒ‰ํ•จ. /[^A-Za-z0-9]/์™€ ๋™์ผ
[^] []์•ˆ์˜ ๋ฌธ์ž์—ด ์•ž์— ^์ด ์“ฐ์ด๋ฉด, []์•ˆ์— ์—†๋Š” ๋ฌธ์ž๋ฅผ ๊ฒ€์ƒ‰ํ•จ

Anchors - ^ and $

^๋Š” ๋ฌธ์ž์—ด์˜ ์ฒ˜์Œ์„ ์˜๋ฏธํ•˜๊ณ , ๋ฌธ์ž์—ด์—์„œ ^๋’ค์— ๋ถ™์€ ๋‹จ์–ด๋กœ ์‹œ์ž‘ํ•˜๋Š” ๋ถ€๋ถ„์„ ์ฐพ๋Š”๋‹ค. ์ผ์น˜ํ•˜๋Š” ๋ถ€๋ถ„์ด ์žˆ์–ด๋”๋ผ๋„, ๊ทธ ๋ถ€๋ถ„์ด ๋ฌธ์ž์—ด์˜ ์‹œ์ž‘ ๋ถ€๋ถ„์ด ์•„๋‹ˆ๋ฉด null์„ ๋ฆฌํ„ดํ•œ๋‹ค.

"coding is fun".match(/^co/); // ['co']
"coding is fun".match(/^fun/); // null

$๋Š” ๋ฌธ์ž์—ด์˜ ๋์„ ์˜๋ฏธํ•˜๊ณ , ๋ฌธ์ž์—ด์—์„œ $์•ž์˜ ํ‘œํ˜„์‹์œผ๋กœ ๋๋‚˜๋Š” ๋ถ€๋ถ„์„ ์ฐพ๋Š”๋‹ค. ^์™€ ๋น„์Šทํ•˜์ง€๋งŒ ^๋Š” ๋ฌธ์ž์—ด์˜ ์‹œ์ž‘์„ ์ฐพ๊ณ , $๋Š” ๋ฌธ์ž์—ด์˜ ๋งˆ์ง€๋ง‰ ๋ถ€๋ถ„์„ ์ฐพ๋Š”๋‹ค. ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ์ผ์น˜ํ•˜๋Š” ๋ถ€๋ถ„์ด ์žˆ๋”๋ผ๋„, ๊ทธ ๋ถ€๋ถ„์ด ๋ฌธ์ž์—ด์˜ ๋๋ถ€๋ถ„์ด ์•„๋‹ˆ๋ฉด null์„ ๋ฆฌํ„ดํ•œ๋‹ค.

"coding is fun".match(/un$/); // ['un']
"coding is fun".match(/is$/); // null
"coding is fun".match(/^coding is fun$/);
// ๋ฌธ์ž์—ด์„ ^ ์™€ $ ๋กœ ๊ฐ์‹ธ์ฃผ๋ฉด ๊ทธ ์‚ฌ์ด์— ๋“ค์–ด๊ฐ„ ๋ฌธ์ž์—ด๊ณผ ์ •ํ™•ํ•˜๊ฒŒ ์ผ์น˜ํ•˜๋Š” ๋ถ€๋ถ„์„ ์ฐพ๋Š”๋‹ค.
// ["coding is fun"]

Quantifiers —*, +, ? and {}

*๋Š” *๋ฐ”๋กœ ์•ž์˜ ๋ฌธ์ž๊ฐ€ 0๋ฒˆ ์ด์ƒ ๋‚˜ํƒ€๋‚˜๋Š” ๊ฒฝ์šฐ๋ฅผ ๊ฒ€์ƒ‰ํ•œ๋‹ค. ์•„๋ž˜์™€ ๊ฐ™์€ ๋ฌธ์ž์—ด์ด ์žˆ์„ ๋•Œ์— /ode*/g ์„ ์‚ฌ์šฉํ•˜๊ฒŒ ๋˜๋ฉด "od"๊ฐ€ ๋“ค์–ด๊ฐ€๋ฉด์„œ ๊ทธ ๋’ค์— "e"๊ฐ€ 0๋ฒˆ ์ด์ƒ ํฌํ•จ๋œ ๋ชจ๋“  ๋ฌธ์ž์—ด์„ ๋ฆฌํ„ดํ•œ๋‹ค.

"co cod code codee coding codeeeeee codingding".match(/ode*/g);
// ["od", "ode", "odee", "od", "odeeeeee", "od"]

+๋„ *์™€ ๊ฐ™์€ ๋ฐฉ์‹์œผ๋กœ ์ž‘๋™ํ•˜๊ณ , ๋‹ค๋งŒ + ๋ฐ”๋กœ ์•ž์˜ ๋ฌธ์ž๊ฐ€ 1๋ฒˆ ์ด์ƒ ๋‚˜ํƒ€๋‚˜๋Š” ๊ฒฝ์šฐ๋ฅผ ๊ฒ€์ƒ‰ํ•œ๋‹ค๋Š” ์ ์ด *๊ณผ ๋‹ค๋ฅผ ๋ฟ์ด๋‹ค.

"co cod code codee coding codeeeeee codingding".match(/ode*/g);
// ["ode", "odee", "odeeeeee"]

?๋Š” * ๋˜๋Š” +์™€ ๋น„์Šทํ•˜์ง€๋งŒ, ? ์•ž์˜ ๋ฌธ์ž๊ฐ€ 0๋ฒˆ ํ˜น์€ 1๋ฒˆ ๋‚˜ํƒ€๋‚˜๋Š” ๊ฒฝ์šฐ๋งŒ ๊ฒ€์ƒ‰ํ•œ๋‹ค. *? ๋˜๋Š” +?์™€ ๊ฐ™์ด ?๋Š” * ํ˜น์€ +์™€ ํ•จ๊ป˜ ์“ฐ๋Š” ๊ฒƒ๋„ ๊ฐ€๋Šฅํ•˜๋‹ค.

"co cod code codee coding codeeeeee codingding".match(/ode?/g);
// ["od", "ode", "ode", "od", "ode", "od"]
"co cod code codee coding codeeeeee codingding".match(/ode*?/g);
// ["od", "od", "od", "od", "od", "od"]
"co cod code codee coding codeeeeee codingding".match(/ode+?/g);
// ["ode", "ode", "ode"]

{}sms *, *?, +, +?์˜ ํ™•์žฅํŒ์œผ๋กœ ์ƒ๊ฐํ•  ์ˆ˜ ์žˆ๋‹ค, *, *?, +, +?๊ฐ€ '0๊ฐœ ์ด์ƒ' ๋˜๋Š” '1๊ฐœ ์ด์ƒ' ๊ฒ€์ƒ‰์ด ์ „๋ถ€์˜€๋˜ ๋ฐ˜๋ฉด, {}๋Š” ์ง์ ‘ ์ˆซ์ž๋ฅผ ๋„ฃ์–ด์„œ ์—ฐ์†๋˜๋Š” ๊ฐœ์ˆ˜๋ฅผ ์„ค์ •ํ•  ์ˆ˜ ์žˆ๋‹ค.

"co cod code codee coding codeeeeee codingding".match(/ode{2}/g);
// 2๊ฐœ์˜ "e"๋ฅผ ํฌํ•จํ•œ ๋ฌธ์ž์—ด์„ ๊ฒ€์ƒ‰ํ•œ๋‹ค.
// ["odee", "odee"]

"co cod code codee coding codeeeeee codingding".match(/ode{2,}/g);
// 2๊ฐœ ์ด์ƒ์˜ "e"๋ฅผ ํฌํ•จํ•œ ๋ฌธ์ž์—ด์„ ๊ฒ€์ƒ‰ํ•œ๋‹ค.
// ["odee", "odeeeeee"]

"co cod code codee coding codeeeeee codingding".match(/ode{2,5}/g);
// 2๊ฐœ ์ด์ƒ 5๊ฐœ ์ดํ•˜์˜ "e"๋ฅผ ํฌํ•จํ•œ ๋ฌธ์ž์—ด์„ ๊ฒ€์ƒ‰ํ•œ๋‹ค.
// ["odee", "odeeeee"]

OR operator

|๋Š” or ์กฐ๊ฑด์œผ๋กœ ๊ฒ€์ƒ‰ํ•˜์—ฌ |์˜ ์™ผ์ชฝ ๋˜๋Š” ์˜ค๋ฅธ์ชฝ์˜ ๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค.

"Cc Oo Dd Ee".match(/O|D/g); // ["O", "D"]
"Cc Oo Dd Ee".match(/c|e/g); // ["c", "e"]
"Cc Oo Dd Ee".match(/D|e/g); // ["D", "e"]
"Ccc Ooo DDd EEeee".match(/D+|e+/g); // + ๋Š” 1๋ฒˆ ์ด์ƒ ๋ฐ˜๋ณต์„ ์˜๋ฏธํ•˜๊ธฐ ๋•Œ๋ฌธ์—
// ["DD", "eee"] ๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค.

Bracket Operator - []

๋Œ€๊ด„ํ˜ธ []์•ˆ์— ๋ช…์‹œ๋œ ๊ฐ’์„ ๊ฒ€์ƒ‰ํ•œ๋‹ค.

[abc] // a or b or c ๋ฅผ ๊ฒ€์ƒ‰ํ•ฉ๋‹ˆ๋‹ค. or(|) Operator ๋กœ ์ž‘์„ฑํ•œ a|b|c ์™€ ๋™์ผํ•˜๊ฒŒ ์ž‘๋™ํ•ฉ๋‹ˆ๋‹ค.
[a-c] // [abc] ์™€ ๋™์ผํ•ฉ๋‹ˆ๋‹ค. - ๋กœ ๊ฒ€์ƒ‰ ๊ตฌ๊ฐ„์„ ์„ค์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

"Ccc Ooo DDd EEeee".match(/[CD]+/g); // [] ์— + ๋“ฑ์˜ ๊ธฐํ˜ธ๋ฅผ ํ•จ๊ป˜ ์‚ฌ์šฉํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค.
// C or D ๊ฐ€ ํ•œ ๋ฒˆ ์ด์ƒ ๋ฐ˜๋ณต๋œ ๋ฌธ์ž์—ด์„ ๋ฐ˜๋ณต ๊ฒ€์ƒ‰ํ•˜๊ธฐ ๋•Œ๋ฌธ์—
// ["C", "DD"] ๊ฐ€ ๋ฐ˜ํ™˜๋ฉ๋‹ˆ๋‹ค.

"Ccc Ooo DDd EEeee".match(/[co]+/g); // ["cc", "oo"]
"Ccc Ooo DDd EEeee".match(/[c-o]+/g); // - ๋•Œ๋ฌธ์— c ~ o ๊ตฌ๊ฐ„์„ ๊ฒ€์ƒ‰ํ•˜์—ฌ
// ["cc", "oo", "d", "eee"] ๊ฐ€ ๋ฐ˜ํ™˜๋œ๋‹ค.

"AA 12 ZZ Ad %% Az !# dd 54 zz".match(/[A-Za-z]+/g); 
// a~z ๋˜๋Š” A~Z ์—์„œ ํ•œ ๋ฒˆ ์ด์ƒ ๋ฐ˜๋ณต๋˜๋Š” ๋ฌธ์ž์—ด์„ ๋ฐ˜๋ณต ๊ฒ€์ƒ‰ํ•˜๊ธฐ ๋•Œ๋ฌธ์—
// ["AA", "ZZ", "Ad", "Az", "dd", "zz"] ๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค.
"AA 12 ZZ Ad %% Az !# dd 54 zz".match(/[A-Z]+/gi);
// flag i ๋Š” ๋Œ€์†Œ๋ฌธ์ž๋ฅผ ๊ตฌ๋ถ„ํ•˜์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์— ์œ„์™€ ๋™์ผํ•œ ๊ฒฐ๊ณผ๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค.
// ["AA", "ZZ", "Ad", "Az", "dd", "zz"]

"AA 12 ZZ Ad %% Az !# dd 54 zz".match(/[0-9]+/g);
// ์ˆซ์ž๋„ ๊ฒ€์ƒ‰ ๊ฐ€๋Šฅํ•˜๋‹ค.
// ["12", "54"]

"aAbB$#67Xz@9".match(/[^a-zA-Z]+/g);
// [] ์•ˆ์— ^ ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด anchor ๋กœ์„œ์˜ ๋ฌธ์ž์—ด์˜ ์ฒ˜์Œ์„ ์ฐพ๋Š”๊ฒƒ์ด ์•„๋‹Œ 
// ๋ถ€์ •์„ ๋‚˜ํƒ€๋‚ด๊ธฐ ๋•Œ๋ฌธ์— [] ์•ˆ์— ์—†๋Š” ๊ฐ’์„ ๊ฒ€์ƒ‰ํ•œ๋‹ค.
// ["$#67", "@9"]

Character classes

\d์˜ d๋Š” digit์„ ์˜๋ฏธํ•˜๋ฉฐ 0 ~ 9 ์‚ฌ์ด์˜ ์ˆซ์ž ํ•˜๋‚˜๋ฅผ ๊ฒ€์ƒ‰ํ•œ๋‹ค. [0-9]์™€ ๋™์ผํ•˜๋‹ค.

\D๋Š” not Digit์„ ์˜๋ฏธํ•˜๋ฉฐ, ์ˆซ์ž๊ฐ€ ์•„๋‹Œ ๋ฌธ์ž ํ•˜๋‚˜๋ฅผ ๊ฒ€์ƒ‰ํ•œ๋‹ค. [^0-9]์™€ ๋™์ผํ•˜๋‹ค.

"abc34".match(/\d/); // ["3"]
"abc34".match(/[0-9]/) // ["3"]
"abc34".match(/\d/g); // ["3", "4"]
"abc34".match(/[0-9]/g) // ["3", "4"]
"abc34".match(/\D/); // ["a"]
"abc34".match(/[^0-9]/); // ["a"]
"abc34".match(/\D/g); // ["a", "b", "c"]
"abc34".match(/[^0-9]/g); // ["a", "b", "c"]

\w๋Š” ์•ŒํŒŒ๋ฒณ ๋Œ€์†Œ๋ฌธ์ž, ์ˆซ์ž, _(underbar) ์ค‘ ํ•˜๋‚˜๋ฅผ ๊ฒ€์ƒ‰ํ•œ๋‹ค. [a-zA-Z0-9_]์™€ ๋™์ผํ•˜๋‹ค.

\W๋Š” ์•ŒํŒŒ๋ฒณ ๋Œ€์†Œ๋ฌธ์ž, ์ˆซ์ž, _(underbar)๊ฐ€ ์•„๋‹Œ ๋ฌธ์ž ํ•˜๋‚˜๋ฅผ ๊ฒ€์ƒ‰ํ•œ๋‹ค. [^a-zA-Z0-9_]์™€ ๋™์ผํ•˜๋‹ค.

"ab3_@A.Kr".match(/\w/); //["a"]
"ab3_@A.Kr".match(/[a-zA-Z0-9_]/) // ["a"]
"ab3_@A.Kr".match(/\w/g); //["a", "b", "3", "_", "A", "K", "r"]
"ab3_@A.Kr".match(/[a-zA-Z0-9_]/g) // ["a", "b", "3", "_", "A", "K", "r"]

"ab3_@A.Kr".match(/\W/); // ["@"]
"ab3_@A.Kr".match(/[^a-zA-Z0-9_]/); // ["@"]
"ab3_@A.Kr".match(/\W/g); // ["@", "."]
"ab3_@A.Kr".match(/[^a-zA-Z0-9_]/g); // ["@", "."]

Grouping and capturing

()๋Š” ๊ทธ๋ฃน์œผ๋กœ ๋ฌถ๋Š”๋‹ค๋Š” ์˜๋ฏธ ์ด์™ธ์—๋„ ๋‹ค๋ฅธ ๋ช‡๊ฐ€์ง€ ์˜๋ฏธ๊ฐ€ ๋” ์žˆ๋‹ค.

๊ทธ๋ฃนํ™”

ํ‘œํ˜„์‹์˜ ์ผ๋ถ€๋ฅผ ()๋กœ ๋ฌถ์–ด์ฃผ๋ฉด ๊ทธ ์•ˆ์˜ ๋‚ด์šฉ์„ ํ•˜๋‚˜๋กœ ๊ทธ๋ฃนํ™”ํ•  ์ˆ˜ ์žˆ๋‹ค.

let co = 'coco';
let cooo = 'cooocooo';

co.match(/co+/); // ["co", index: 0, input: "coco", groups: undefined]
cooo.match(/co+/); // ["cooo", index: 0, input: "cooocooo", groups: undefined]

co.match(/(co)+/); // ["coco", "co", index: 0, input: "coco", groups: undefined]
cooo.match(/(co)+/); // ["co", "co", index: 0, input: "cooocooo", groups: undefined]

co+๋Š” 'c'๋ฅผ ๊ฒ€์ƒ‰ํ•˜๊ณ  +๊ฐ€ 'o'๋ฅผ 1ํšŒ ์ด์ƒ ์—ฐ์†์œผ๋กœ ๋ฐ˜๋ณต๋˜๋Š” ๋ฌธ์ž๋ฅผ ๊ฒ€์ƒ‰ํ•ด ์ฃผ๊ธฐ ๋•Œ๋ฌธ์— 'cooo'๊ฐ€ ๋ฐ˜ํ™˜๋œ๋‹ค. ํ•˜์ง€๋งŒ (co)+๋Š” 'c'์™€ 'o'๋ฅผ ๊ทธ๋ฃนํ™”ํ•˜์—ฌ 'co'๋ฅผ ๋‹จ์œ„๋กœ 1ํšŒ ์ด์ƒ ๋ฐ˜๋ณต์„ ๊ฒ€์ƒ‰ํ•˜๊ธฐ ๋•Œ๋ฌธ์— 'coco'๊ฐ€ ๋ฐ˜ํ™˜๋œ๋‹ค.

์บก์ฒ˜

()๋กœ ๊ทธ๋ฃนํ™”ํ•œ๋‹ค๊ณ  ํ–ˆ๊ณ , ์ด๋ฅผ ์บก์ฒ˜ํ•œ๋‹ค๋ผ๊ณ  ํ•œ๋‹ค.

co.match(/(co)+/); // ["coco", "co", index: 0, input: "coco", groups: undefined]
  1. ()๋กœ 'co'๋ฅผ ์บก์ฒ˜
  2. ์บก์ฒ˜ํ•œ 'co'๋Š” ์ผ๋‹จ ๋‹น์žฅ ์‚ฌ์šฉํ•˜์ง€ ์•Š๊ณ , +๊ฐ€ 'co'์˜ 1ํšŒ ์ด์ƒ ์—ฐ์† ๋ฐ˜๋ณต์„ ๊ฒ€์ƒ‰
  3. ์ด๋ ‡๊ฒŒ ์บก์ฒ˜ ์ด์™ธ ํ‘œํ˜„์‹์ด ๋ชจ๋‘ ์ž‘๋™ํ•˜๊ณ  ๋‚˜๋ฉด, ์บก์ฒ˜ํ•ด ๋‘์—ˆ๋˜ 'co'๋ฅผ ๊ฒ€์ƒ‰

๋”ฐ๋ผ์„œ 2๋ฒˆ ๊ณผ์ •์— ์˜ํ•ด 'coco'๊ฐ€ ๋ฐ˜ํ™˜๋˜๊ณ , 3๋ฒˆ์— ์˜ํ•ด 'co'๊ฐ€ ๋ฐ˜ํ™˜๋˜๋Š” ๊ฒƒ์ด๋‹ค.

 

"2021code".match(/(\d+)(\w)/);
// ["2021c", "2021", "c", index: 0, input: "2021code", groups: undefined]
  1. ()์•ˆ์— ํ‘œํ˜„์‹์„ ์ˆœ์„œ๋Œ€๋กœ ์บก์ฒ˜ => \d+์™€ \w
  2. ์บก์ฒ˜ ํ›„ ๋‚จ์€ ํ‘œํ˜„์‹์œผ๋กœ ๊ฒ€์ƒ‰ => ์ด๋ฒˆ ์˜ˆ์‹œ์—๋Š” ๋‚จ์€ ํ‘œํ˜„์‹์€ ์—†๋‹ค.
  3. \d๋กœ ์ˆซ์ž๋ฅผ ๊ฒ€์ƒ‰ํ•˜๋˜ +๋กœ 1๊ฐœ ์ด์ƒ ์—ฐ์†๋˜๋Š” ์ˆซ์ž๋ฅผ ๊ฒ€์ƒ‰ => 2021
  4. \w๋กœ ๋ฌธ์ž๋ฅผ ๊ฒ€์ƒ‰ => c
  5. 3๋ฒˆ๊ณผ 4๋ฒˆ์ด ์กฐํ•ฉ๋˜์–ด '2020c'๊ฐ€ ๋ฐ˜ํ™˜
  6. ์ฒซ ๋ฒˆ์งธ ์บก์ฒ˜ํ•œ (\d+)๋กœ ์ธํ•ด 2021์ด ๋ฐ˜ํ™˜
  7. ๋‘ ๋ฒˆ์งธ ์บก์ฒ˜ํ•œ (\w)๋กœ ์ธํ•ด 'c'๊ฐ€ ๋ฐ˜ํ™˜

๋ฌธ์ž์—ด ๋Œ€์ฒด ์‹œ ์บก์ฒ˜๋œ ๊ฐ’ ์ฐธ์กฐ

์บก์ฒ˜๋œ ๊ฐ’์€ replace() ๋ฉ”์†Œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ฌธ์ž ์น˜ํ™˜ ์‹œ ์ฐธ์กฐ ํŒจํ„ด์œผ๋กœ ์‚ฌ์šฉ๋  ์ˆ˜ ์žˆ๋‹ค.

"code.states".replace(/(\w+)\.(\w+)/, "$2.$1"); //states.code

์šฐ์„  ์ฒซ ๋ฒˆ์งธ (\w+) ๊ฐ€ code ๋ฅผ ์บก์ฒ˜ํ•˜๊ณ , ๋‘ ๋ฒˆ์งธ (\w+) ๊ฐ€ states ๋ฅผ ์บก์ฒ˜ํ•ฉ๋‹ˆ๋‹ค. ( /(\w+)\ ์™€ (\w+)/\์‚ฌ์ด์˜ . ์€ . ์•ž์— ์—ญ์Šฌ๋ž˜์‹œ๊ฐ€ ์‚ฌ์šฉ๋˜์—ˆ๊ธฐ ๋•Œ๋ฌธ์— '์ž„์˜์˜ ํ•œ ๋ฌธ์ž'๊ฐ€ ์•„๋‹Œ ๊ธฐํ˜ธ๋กœ์„œ์˜ ์˜จ์  . ์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค.) ๊ฐ ์บก์ฒ˜๋œ ๊ฐ’์€ ์ฒซ ๋ฒˆ์งธ๋Š” $1 ์ด ์ฐธ์กฐ, ๋‘ ๋ฒˆ์งธ๋Š” $2 ์ด ์ฐธ์กฐํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์ด ์ฐธ์กฐ๋œ ๊ฐ’์„ "$2.$1" ์ด ๋Œ€์ฒดํ•˜๊ฒŒ ๋˜์–ด code ์™€ states ๊ฐ€ ๋’ค๋ฐ”๋€ "states.code" ๊ฐ€ ๋ฐ˜ํ™˜๋ฉ๋‹ˆ๋‹ค.

non-capturing

()๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๊ทธ๋ฃนํ™”์™€ ์บก์ฒ˜๋ฅผ ํ•œ๋‹ค๊ณ  ํ–ˆ๋‹ค. ํ•˜์ง€๋งŒ (?:)๋กœ ์‚ฌ์šฉํ•˜๋ฉด ๊ทธ๋ฃน์€ ๋งŒ๋“ค์ง€๋งŒ ์บก์ฒ˜๋Š” ํ•˜์ง€ ์•Š๋Š”๋‹ค.

let co = 'coco';

co.match(/(co)+/); // ["coco", "co", index: 0, input: "coco", groups: undefined]

co.match(/(?:co)+/); 
// ["coco", index: 0, input: "coco", groups: undefined]

lookahead

(?=)๋Š” ๊ฒ€์ƒ‰ํ•˜๋ ค๋Š” ๋ฌธ์ž์—ด์— (?=์—ฌ๊ธฐ)์— ์ผ์น˜ํ•˜๋Š” ๋ฌธ์ž๊ฐ€ ์žˆ์–ด์•ผ (?=์—ฌ๊ธฐ)์•ž์˜ ๋ฌธ์ž์—ด์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค.

"abcde".match(/ab(?=c)/);
// ab ๊ฐ€ c ์•ž์— ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ["ab"] ๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค.
"abcde".match(/ab(?=d)/);
// d ์˜ ์•ž์€ "abc" ์ด๊ธฐ ๋•Œ๋ฌธ์— null ์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค.

negated lookahead

(?!)๋Š” (?=)์˜ ๋ถ€์ •์ด๋‹ค.

"abcde".match(/ab(?!c)/); // null
"abcde".match(/ab(?!d)/); // ["ab"]

์ •๊ทœํ‘œํ˜„์‹์€ ์‘์šฉ์„ ํ†ตํ•ด ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ๋ฟ ์•„๋‹ˆ๋ผ ๋ฐ์ดํ„ฐ ์Šคํฌ๋ž˜ํ•‘, ๋ฌธ์ž์—ด ํŒŒ์‹ฑ ๋“ฑ๊ณผ ๊ฐ™์€ ๋‹ค์–‘ํ•œ ์ƒํ™ฉ์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ์‚ฌ์šฉ๋ฒ•์„ ์ˆ™์ง€ํ•ด ๋†“์œผ๋ฉด ์•Œ๊ณ ๋ฆฌ์ฆ˜ ๋ฌธ์ œ์—์„œ ๋”์šฑ ๋‹ค์–‘ํ•œ ํ•ด๊ฒฐ ์•„์ด๋””์–ด๋ฅผ ์–ป์„ ์ˆ˜ ์žˆ๋‹ค.

 

์ •๊ทœํ‘œํ˜„์‹์„ ์ •๋ฆฌํ•˜์ž ํ•ด๋†“๊ณ  ๋ฏธ๋ฃจ๋‹ค๊ฐ€ ๊ฒฐ๊ตญ Code States์—์„œ ๋‹ค๋ฃจ๋Š” ๋ถ€๋ถ„์ด ์žˆ์—ˆ๋‹ค. ์œ„์˜ ๋‚ด์šฉ์€ ๋‹จ์ˆœํžˆ Code States์— ์ž‘์„ฑ๋œ ๋‚ด์šฉ์„ ์˜ฎ๊ฒจ ์ ์€ ๊ฒƒ์ด์ง€๋งŒ, ๋‚˜์ค‘์— ์‚ฌ์šฉํ•ด๋ณด๊ณ  ์Šค์Šค๋กœ ์ •๋ฆฌํ•ด๋‘๋Š” ์‹œ๊ฐ„์„ ๊ฐ–๋„๋ก ํ•ด์•ผ๊ฒ ๋‹ค.