slev
Show HN: I made native JavaScript regexes competitive with the best re flavors
https://github.com/slevithan/regex
I'm a longtime regex superfan, having coauthored O'Reilly Media's Regular Expressions Cookbook and creating/contributing to a variety of open source regex tools. I also love JavaScript, but historically its regexes have been underpowered compared to other modern regex flavors. So I recently created a lightweight library that upgrades native JS regexes with key features that, when combined with...
Show HN: Awesome Regex – Best tools/tuts/libs/etc. for all major regex flavors
https://github.com/slevithan/awesome-regex
I created a curated and opinionated list of the best regular expression tools, tutorials, libraries, and many other resources. It covers all major regex flavors, and currently includes especially deep coverage of regular expressions in JavaScript (including a concise history of all regex features added to JavaScript in ES6 through ES2024, plus active proposals for the future).
It’s still tiny (nothing similar comes close, even with libraries that support far fewer URI parts, types, and edge cases), and it includes several advantages over JavaScript's built-in `URL` constructor:
* parseUri gives you many additional properties (authority, userinfo, subdomain, domain, tld, resource, directory, filename, suffix) that aren’t available from `URL`.
* `URL` throws e.g. if not given a protocol, and in many other cases of valid (but not supported) and invalid URIs. parseUri makes a best case effort even with partial or invalid URIs and is extremely good with edge cases.
* `URL`’s rules don’t allow correctly handling many non-web protocols. For example, `URL` doesn’t throw on any of 'git://localhost:1234', 'ssh://[email protected]', or 't2ab:///path/entry', but it also doesn’t get their details correct since it treats everything after : up to ? or # as part of the pathname.
* parseUri includes a “friendly” parsing mode (in addition to its default mode) that handles human-friendly URLs like 'example.com/index.html' as expected.
* parseUri includes partial/extensible support for second-level domains like in '//example.co.uk'.
So although it’s needed less often these days because of the built-in `URL`, if `URL` is ever not enough for your needs, this is an extremely accurate, flexible, and lightweight option.
The parseUri demo page lets you easily test results and compare them with `URL`: https://slevithan.github.io/parseuri/demo/