it should(could) have newlines for readability. and is genererally an underappreciated feature that leads to people thinking that regex is crazy and unreadable.
I didn’t know about this so I tried testing it out. Yes, this is possible, but requires enabling a specific flag (x when it comes to regexp2) assuming the engine even supports this feature.
also comments. which can be very simple…like metadata about boundary,membership,grouping, or hierarchy.
its supported in most languages except javascript and plain grep.
but it doesnt serve a programmatic use… so even if its a hella useful single char or digit, that massively boosts readability… some people would argue that it’s extra/junk
Holy overengineering, Batman. IP addresses of all things are trivially parseable into fixed-length byte sequences. Just do that and use a search tree. Or, IDK; this is an extremely solved problem, there are probably even better solutions out there – but I promise you text regex is involved in none of the good ones.
Even for actual string matching, any decent regex engine will compile and optimise an alternation a|b|c|... better than this text wrangling will. Unless you have actual benchmarks showing this gives you an advantage with the engine you’re using, you’re just introducing complexity for no gain.
Here is an example. Given the following list of strings:
list2regexp will return the following pattern:
it should(could) have newlines for readability. and is genererally an underappreciated feature that leads to people thinking that regex is crazy and unreadable.
I didn’t know about this so I tried testing it out. Yes, this is possible, but requires enabling a specific flag (x when it comes to regexp2) assuming the engine even supports this feature.
also comments. which can be very simple…like metadata about boundary,membership,grouping, or hierarchy.
its supported in most languages except javascript and plain grep.
but it doesnt serve a programmatic use… so even if its a hella useful single char or digit, that massively boosts readability… some people would argue that it’s extra/junk
… should do the trick.
Why? 🤔
In my case, to efficiently match against a large number of IP addresses and IP address ranges:
https://codeberg.org/tslocum/sriracha/src/commit/5bf24b0daabd058c2714427da17c7ea16b7cd43a/internal/server/server.go#L447
Holy overengineering, Batman. IP addresses of all things are trivially parseable into fixed-length byte sequences. Just do that and use a search tree. Or, IDK; this is an extremely solved problem, there are probably even better solutions out there – but I promise you text regex is involved in none of the good ones.
Even for actual string matching, any decent regex engine will compile and optimise an alternation
a|b|c|...better than this text wrangling will. Unless you have actual benchmarks showing this gives you an advantage with the engine you’re using, you’re just introducing complexity for no gain.Also of note. Regexlicensing.org has issued no licences to date for use of regex in production environments
https://regexlicensing.org/license/
Not much substance to their argument, mostly just whining. Funny website, though.
It’s called “allowlist” and “denylist” nowadays as it’s easier to understand for non-native speakers and not racist.
I feel like there’s an easier and faster way to match IP addresses than regex, e.g. the search tree apparia suggested. At least use bytes to match 😄
https://en.wikipedia.org/wiki/Blacklist_(computing)#Controversy_over_terminology
(See the section that follows for more context.)
Yes, but does it really hurt you to make your software more accessible?
What good arguments do you have for the term blacklist?
“Denylist” is easier to understand and doesn’t spark discussions. Nobody will be offended, whether it’s technically correct to be offended or not.
I’m not a person of colour but your answer still insults me, because it’s so tone deaf.
I think the list of strings with pipes between each element would be shorter than this huge unreadable blob
Being pretty or short is not a goal of this project, nor do I see the value in such goals.
Pretty and short probably also have better performance.
Did you manually come up with a prettier regex to compare against?