-
02. ๋ฌธ์ ํ๋ ์ฐพ๊ธฐ!๐ง codingtest/์ ๊ทํํ์(regexp) 2022. 8. 27. 18:56728x90
๋ชจ๋ ๋ฌธ์ ์ฐพ๊ธฐ
- ๋ง์นจํ(.) : ์๋ฌด ๋ฌธ์ ํ๋ ์ ์ผ์น
const str = "Hello, my name is Yelim. I really hope you guys have good day~!"; function test(e) { return console.log(e.match(".lim")[0]); } test(str); // elim
- ์ฐ์ ๋ง์นจํ ๋๊ฐ (..) : ๋ถ์ด์๋ ๋ฌธ์ ๋๊ฐ ์ ์ผ์น
const str = "Hello, my name is Yelim. I really hope you guys have good day~!"; function test(e) { return console.log(e.match("..lim")[0]); } test(str); // Yelim
- ์ด์ค์ผ์ดํ(\) ์ฌ์ฉํ ๋ง์นจํ(.) : ๋ง์นจํ(.) ์์ฒด๋ฅผ ์ฐพ์์ ์๋ค.
const str = "Hello, my name is Yelim. I really hope you guys have good day~!"; function test(e) { return console.log(e.match("m\\.")[0]); } // ์ญ์ฌ๋์(\) ์์ฒด๊ฐ ์ด์ค์ผ์ดํ ๋๋ฏ๋ก ์ธ์์ด ์๋๊ธฐ ๋๋ฌธ์ ๋ค๋ฅธ ๋ฌธ์๋ฅผ ์ด์ค์ผ์ดํ ํด์ค๋๋ ์ญ์ฌ๋์(\) ๋๋ฒ์ฌ์ฉ test(str); // m.
const arr = [ "yelim1.jpg", "nun2.jpg", "dong1.xls", "don2.xls", "dong3.xls", "don4.xls", "sal.png", "sal2.png", ]; function test(e) { for (let i of e) { i.match("don..") && console.log(i.match("don..")[0]); } } test(arr); // dong1 // don2. // dong3 // don4.
์ญ์ฌ๋์(\)
๋ฉํ ๋ฌธ์๋ค(๋ฌธ์ ๊ทธ๋๋ก ์ฌ์ฉ๋์ง ์๊ณ ํน๋ณํ ์๋ฏธ๋ฅผ ์ง๋๋ ๋ฌธ์๋ฅผ ์นญํจ)
๋ถํธ ๊ธฐ๋ฅ . ์๋ฌด ๋ฌธ์ ํ๋ ์ ์ผ์น .. ๋ถ์ด์๋ ๋ฌธ์ ๋๊ฐ ์ ์ผ์น \. ์์ฒด๋ฅผ ์ฐพ์์ ์๋ค. '๐ง codingtest > ์ ๊ทํํ์(regexp)' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
06. ์์น ์ฐพ๊ธฐ (0) 2022.09.03 05. ๋ฐ๋ณต ์ฐพ๊ธฐ (0) 2022.09.03 04. ๋ฉํ ๋ฌธ์ ์ฌ์ฉํ๊ธฐ! (0) 2022.09.03 03. ๋ฌธ์ ์งํฉ์ผ๋ก ์ฐพ๊ธฐ! (0) 2022.09.03 01. ์ ๊ทํํ์ ์์! (0) 2022.08.27