you are viewing a single comment's thread
view the rest of the comments
[–] [S] 9 points 1 month ago (15 children)

Here is an example. Given the following list of strings:

1.2.3.4
127.0.0.1
127.0.0.2
127.0.0.11
128.0.0.1
125.0.0.*
200.0.0.1
2001:0db8:85a3:0000:0000:8a2e:0370:1300
2001:0db8:85a3:0000:0000:8a2e:0370:1330
2001:0db8:85a3:0000:0000:8a2e:0370:1337
あいうえお
あいうえこ
😃😁😆😐
😃😁😆
😃😁🤣

list2regexp will return the following pattern:

^(?:1(?:(?:\.(?:2(?:\.(?:3(?:\.(?:4))))))|(?:2(?:(?:5(?:\.(?:0(?:\.(?:0(?:\.(?:.*)))))))|(?:7(?:\.(?:0(?:\.(?:0(?:\.(?:(?:1(?:|(?:1)))|(?:2))))))))|(?:8(?:\.(?:0(?:\.(?:0(?:\.(?:1)))))))))))|(?:2(?:0(?:0(?:(?:\.(?:0(?:\.(?:0(?:\.(?:1))))))|(?:1(?::(?:0(?:d(?:b(?:8(?::(?:8(?:5(?:a(?:3(?::(?:0(?:0(?:0(?:0(?::(?:0(?:0(?:0(?:0(?::(?:8(?:a(?:2(?:e(?::(?:0(?:3(?:7(?:0(?::(?:1(?:3(?:(?:0(?:0))|(?:3(?:(?:0|7))))))))))))))))))))))))))))))))))))))))))|(?:あ(?:い(?:う(?:え(?:(?:お|こ))))))|(?:😃(?:😁(?:(?:😆(?:|(?:😐)))|(?:🤣))))$
  • source
  • hideshow 15 child comments
  • [–] 4 points 1 month ago (7 children)
  • [–] [S] 4 points 1 month ago (6 children)
  • [–] 7 points 1 month ago (2 children)

    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.

  • source
  • parent
  • hideshow 2 child comments
  • [–] 2 points 1 month ago (2 children)

    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 😄

  • source
  • parent
  • hideshow 2 child comments
  • [–] [S] 2 points 1 month ago* (1 child)

    The term's connection with racism, as well as the value in avoiding its use has been disputed.

    https://en.wikipedia.org/wiki/Blacklist_%28computing%29#Controversy_over_terminology

    (See the section that follows for more context.)

  • source
  • parent
  • hideshow 1 child comment
  • [–] 1 point 1 month ago

    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.

  • source
  • parent
  • [–] 2 points 1 month ago (2 children)

    I think the list of strings with pipes between each element would be shorter than this huge unreadable blob

  • source
  • parent
  • hideshow 2 child comments
  • [–] 2 points 1 month ago* (2 children)

    it should(could) have newlines for readability. and is genererally an underappreciated feature that leads to people thinking that regex is crazy and unreadable.

  • source
  • parent
  • hideshow 2 child comments
  • [–] [S] 1 point 1 month ago* (1 child)

    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.

  • source
  • parent
  • hideshow 1 child comment
  • [–] 2 points 1 month ago*

    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

  • source
  • parent