Technical/React
[React] Regex/정규표현식/Regular Expression
sga8
2021. 12. 10. 16:16
728x90
EX) [2021-12-10][16:04:32] 와 같은 Date에 대괄호가 쳐져있을 때의 처리
대괄호를 제거 하여 내부의 값을 빼어내기 위함.
let splitDate = exampleDate.match(/\[[^\]]*\]/g);
const startDate = splitDate[0].replace(/[\[\]]/g, "");
const startTime = splitDate[1].replace(/[\[\]]/g, "");
위의 예시 [2021-12-10][16:04:32] 를 적용할 경우,
splitDate = [ "[2021-12-01]", "[16:04:32]" ]; // Array
startDate = "2021-12-01";
startTime = "16:04:32";
728x90