-
-
정규식을 테스트 할 수 있는 사이트 (https://regex101.com/)
-
시각화해서 결과를 보여주고, 정규식에 대한 설명도 자세히 있고, 완성된 정규식을 바로 쓸 수 있게 코드로도 만들어준다.
-
URL 주소 match를 위한 정규식 (https://tools.ietf.org/html/rfc3986#appendix-B)
-
요소별로 그룹으로 묶인다. 해당하는 그룹이 없을 경우 undefined
1234567891011121314151617181920const url = 'http://github.com/p/a/t/h?query=string';const regex = /^(([^:\/?#]+):)?(\/\/([^\/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?/g;const matches = regex.exec(url)matches.forEach(cur => {console.log(cur)});/* 결과'http://github.com/p/a/t/h?query=string''http:''http''//github.com''github.com''/p/a/t/h''?query=string''query=string'undefinedundefined*/cs
-
-
-
'자바스크립트' 카테고리의 다른 글
[javascript] 현재 위치 기반 날씨 알려주기 (0) | 2019.08.14 |
---|