Problem
https://www.hackerrank.com/challenges/js10-regexp-1/problem
My solution
function regexVar() {
/*
* Declare a RegExp object variable named 're'
* It must match a string that starts and ends with the same vowel (i.e., {a, e, i, o, u})
*/
const re = /^([aeiou]).*\1$/
/*
* Do not remove the return statement
*/
return re;
}์ญ์ฐธ์กฐ(backreferences)
์ ๊ท ํํ์์์๋ ํจํด์ ์ผ๋ถ๋ฅผ ํ์ ํํ์์ผ๋ก ๋ฌถ์ผ๋ฉด, ์ฒซ๋ฒ์งธ๋ก ๋ํ๋๋ ๋ถ๋ถ ๋ฌธ์์ด์ ์ฐพ์ ๋ค์ ์ญ์ฐธ์กฐ๋ฅผ ํตํด ์ดํ์ ๋ํ๋๋ ๋ถ๋ถ ๋ฌธ์์ด์ ์ฐพ์ ์ ์๋ค. ์ด๋, ๊ฐ ํ์ ํํ์์ ๋ฒํธ๋ก ์๋ณ๋๋ค. ์ด ์ญ์ฐธ์กฐ๋ฅผ ํตํด์, ์ ์ชฝ์์ ํ๋ฒ ์ฐ์๋ ๋ฌธ์์ด์ ์ฐพ์ ์ ์๋ค.
\1 ๋ก ( ) ๊ทธ๋ฃน์ ์ํด ์บก์ณ๋ ์ฒซ๋ฒ์งธ ๋ด์ฉ์ ์ฐธ์กฐํ ์ ์๋ค.
Reg. Expression:
`\b([a-z]+) \1\b
Text:
why so so serious
์ถ์ฒ: https://blog.hexabrain.net/204 [๋๋์ง ์๋ ํ๋ก๊ทธ๋๋ฐ ์ผ๊ธฐ]