- 정규 표현식, 정규식
- 정규식은 문자열에서 특정 패턴을 찾는데 사용
\d : digits
\w : [a-zA-Z0-9_]
. : all
\s : whitespaces
// : pattern
/.*/g : global
/.*/i : ignore case
/.*/m : multi line
[abc] : Matches either an a, b or c character
[^abc] : Matches any character except for an a, b or c
(...) : Capture everything enclosed
(a|b) : a or b
a? : Zero or one of a
a* : Zero or more of a
a+ : One or more of a
a{3} : Matches exactly 3 consecutive a characters.
a{3,} : Matches at least 3 consecutive a characters.
a{3,5} : Matches between 3 and 5 consecutive a characters.
\b : word boundary
^ : line start
$ : line end
const re = /(\w+)\s(\w+)/;
const str = 'John Smith';
const result = str.replace(re, '$2, $1');
RegExp.$1;
RegExp.$2;
result;