home.social

#regexps — Public Fediverse posts

Live and recent posts from across the Fediverse tagged #regexps, aggregated by home.social.

  1. Empty matches in Python’s `re` module

    blog.narf.ssji.net/2025/04/30/

    Python’s `re.sub` method has a weird, though documented, behaviour.

    Replacements for empty-matching patterns such as `/.*/` applied to a non-empty string will lead to two matches. The replacement will therefore be applied twice.

    A simple fix is to make sure the pattern is not empty-matching, e.g. `/.+/`.

    #debugging #Python #regexps #sed

  2. Best answer on regexps ever? 🧐 😎

    - What is the plural form of regex?

    - If you've used more than one of them, you'll know that the plural of "regex" is "regrets." – cjs (Mar 14, 2022 at 23:46)

    #regex #regexps #programmer #programming #devops #regularexpression

  3. Extended are great for place names like "Wellesley" where you can not remember if it's Welesley, Welleseley, Wellesselley, Welleslley, or Welesslley to save your dadburn life. ;)

    /wel+es+e?l+ey/ !!!

    cc: @amin

  4. @hschne I think a lot of folks know about it, but there aren't too many use cases in my own code where it isn't easier just to assign capture groups to variables post facto. Plus, I'm one of those people that think #regex is often abused when simple matches followed by code is better than really complicated #regexps.

    Plus, "shiny and cool" isn't always better than readable, and named capture groups just hurt my eyes. 😎

  5. @regehr @commodore @dev There is even a (low-severity, a/k/a “cruel”) #PerlCritic policy to discourage everything but $_, @_, $], and numbered #RegularExpression capture variables: metacpan.org/pod/Perl::Critic:

    metacpan.org/pod/Perl::Critic: already protects you against the performance-sapping $`, $&, and $' match variables

    And you can configure your own prohibited list with metacpan.org/pod/Perl::Critic:

    #Perl #RegEx #RegExp #RegExes #RegExps

  6. Spent half a day polishing complex #regexps in #vim . And they work too, but perl has a little different standard, so I'm basically stuck in grep -p punching a file until it works. As they say in #taoup , sometimes you just have to brute force prototype. #unix #bashcore #hobbylinguist #hobbytranslator

  7. Spent half a day polishing complex #regexps in #vim . And they work too, but perl has a little different standard, so I'm basically stuck in grep -p punching a file until it works. As they say in #taoup , sometimes you just have to brute force prototype. #unix #bashcore #hobbylinguist #hobbytranslator

  8. Spent half a day polishing complex #regexps in #vim . And they work too, but perl has a little different standard, so I'm basically stuck in grep -p punching a file until it works. As they say in #taoup , sometimes you just have to brute force prototype. #unix #bashcore #hobbylinguist #hobbytranslator

  9. Spent half a day polishing complex #regexps in #vim . And they work too, but perl has a little different standard, so I'm basically stuck in grep -p punching a file until it works. As they say in #taoup , sometimes you just have to brute force prototype. #unix #bashcore #hobbylinguist #hobbytranslator

  10. Spent half a day polishing complex #regexps in #vim . And they work too, but perl has a little different standard, so I'm basically stuck in grep -p punching a file until it works. As they say in #taoup , sometimes you just have to brute force prototype. #unix #bashcore #hobbylinguist #hobbytranslator

  11. @Codely @drupler It helps to build your complicated #RegularExpressions in pieces and store them in separate variables. You can then test them in isolation and not be confused when you concatenate them together for your actual matching.

    Both #PHP and #JavaScript also support named capture groups if you’re doing replacements. They’re a lot more readable.

    Also, PHP’s #PCRE-based engine has a PCRE_EXTENDED flag that lets you add whitespace, newlines, and comments.

    #regexes #regexps

  12. In the absence of #Mastodon #filter #regexps, my anti-twitter-RTs filter is now

    twitter.com/

    The trailing backslash catches links to tweets (twitter.com/screenname/12345 etc) but allows other mentions of twitter.com, e.g., a username.

  13. @sjn @cb 99% of the “#Perl is line noise” complaints are because of unformatted #RegularExpressions. Every language worth anything eventually supports them, but only @Perl (and #awk, earlier) makes them first-class citizens. And with Perl you can format and comment them for readability: perldoc.perl.org/perlretut#Emb

    We format the rest of our code for humans. Why not #regexps?

    #PerlCritic can warn against bad regexps: metacpan.org/search?size=200&q

    #regex #regexes #programming #coding #SoftwareDevelopment

  14. @randomatic @[email protected] @HaplogroupNews @[email protected] A previous employer of mine used re::engine::RE2 for many things, because a) you can cap the memory usage to avoid #DoS attacks, and b) the lead developer was all about premature optimization. metacpan.org/pod/re::engine::R

    But you can’t use the /x flag for better readability, and we ran into some nasty #Unicode bugs and had to fall back to regular Perl #RegExps in those cases.