Regular Expressions 101

Community Library Entry

0

Regular Expression
ECMAScript (JavaScript)

/
^(?:(https?:\/\/)?([^:/$]{1,})(?::(\d{1,}))?(?:($|\/(?:[^?#]{0,}))?((?:\?(?:[^#]{1,}))?)?(?:(#(?:.*)?)?|$)))$
/
g

Description

Parse and split in groups URL parts

https://www.pnukee.com.br:443/user/1?v=1#id

Group 0 = Full entry (https://pnukee.com.br:80/user/1?v=1#id) Group 1 = Protocol = (http:// or https://) Group 2 = Host and TLD Domain = (www.pnukee.com or www.pnukee.com.br) Group 3 = Port (if exists) = (443) Group 4 = Path (if exists) = (/user/1) Group 5 = Search (if exists) = (v=1) Group 6 = hash (if exists) = (#id)

Submitted by Eleison Christiano - 7 years ago