Does this regex recognize a port, like :8080, in the URL?
No. The host class `[\w.-]+` does not include `:`, so as soon as the pattern hits the port colon, it stops capturing right there. `https://example.com:8080/path` only matches as `https://example.com`, with no port and no path.
Does the regex capture the fragment (the anchor after #) of the URL?
No. The path class accepts `?`, `%`, `&` and `=`, but not `#`, so everything after the fragment symbol is left out of the result, even when the query and path before it match normally.
Why use new URL() instead of this regex to process a URL?
`new URL()` splits the string into `protocol`, `hostname`, `port`, `pathname`, `search` and `hash`, already ready to use, understands port and fragment natively, and throws on an invalid URL. This regex is for spotting a loose URL inside text, not for safely taking it apart.