1678. Goal Parser Interpretation
문제
문자열 데이터 command가 매개변수로 주어질 때, 조건을 만족하는 함수 짜기
조건
1. G => "G"
2. () => "o"
3. (al) => "al"
가정
1. command의 길이는 1이상 100이하
2. command는 "G","()" and/or "(al)"로 이루어짐
풀이
var interpret = function(command) { const re1 = new RegExp('\\((al)\\)','g'); const re2 = new RegExp('\\(()\\)','g'); const result = command.replace(re1,"al").replace(re2,"o"); return result; };
정규표현식
()가 포함되어있는 문자열을 찾는 표현식은 따로 설정해줘야 함 **new Regex('\\((문자)\\)`)