#regexps — Public Fediverse posts
Live and recent posts from across the Fediverse tagged #regexps, aggregated by home.social.
-
Empty matches in Python’s `re` module
https://blog.narf.ssji.net/2025/04/30/empty-matches-in-pythons-re-module/
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. `/.+/`.
-
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
-
@neustradamus #PCRE continues to be a misnomer; it’s a modified subset of #Perl #RegularExpressions with dozens of differences: https://pcre.org/current/doc/html/pcre2compat.html
It's not "(C)ompatible." Accept no substitutes: https://perldoc.perl.org/perlre
#PCRE2 #PerlIncompatibleRegularExpressions #RegularExpression #RegExes #RegExps #regex #regexp
-
@neustradamus #PCRE continues to be a misnomer; it’s a modified subset of #Perl #RegularExpressions with dozens of differences: https://pcre.org/current/doc/html/pcre2compat.html
It's not "(C)ompatible." Accept no substitutes: https://perldoc.perl.org/perlre
#PCRE2 #PerlIncompatibleRegularExpressions #RegularExpression #RegExes #RegExps #regex #regexp
-
@neustradamus #PCRE continues to be a misnomer; it’s a modified subset of #Perl #RegularExpressions with dozens of differences: https://pcre.org/current/doc/html/pcre2compat.html
It's not "(C)ompatible." Accept no substitutes: https://perldoc.perl.org/perlre
#PCRE2 #PerlIncompatibleRegularExpressions #RegularExpression #RegExes #RegExps #regex #regexp
-
@neustradamus #PCRE continues to be a misnomer; it’s a modified subset of #Perl #RegularExpressions with dozens of differences: https://pcre.org/current/doc/html/pcre2compat.html
It's not "(C)ompatible." Accept no substitutes: https://perldoc.perl.org/perlre
#PCRE2 #PerlIncompatibleRegularExpressions #RegularExpression #RegExes #RegExps #regex #regexp
-
@neustradamus #PCRE continues to be a misnomer; it’s a modified subset of #Perl #RegularExpressions with dozens of differences: https://pcre.org/current/doc/html/pcre2compat.html
It's not "(C)ompatible." Accept no substitutes: https://perldoc.perl.org/perlre
#PCRE2 #PerlIncompatibleRegularExpressions #RegularExpression #RegExes #RegExps #regex #regexp
-
@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. 😎
-
Any #RakuLang core hackers want to take up this challenge?
#RegularExpressions #RegExps #RegExes #RegEx https://ruby.social/@gd/110718818730295923
-
@regehr @commodore @dev There is even a (low-severity, a/k/a “cruel”) #PerlCritic policy to discourage everything but $_, @_, $], and numbered #RegularExpression capture variables: https://metacpan.org/pod/Perl::Critic::Policy::Variables::ProhibitPunctuationVars
https://metacpan.org/pod/Perl::Critic::Policy::Variables::ProhibitMatchVars already protects you against the performance-sapping $`, $&, and $' match variables
And you can configure your own prohibited list with https://metacpan.org/pod/Perl::Critic::Policy::Variables::ProhibitEvilVariables
-
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
-
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
-
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
-
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
-
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
-
@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.
-
@Perl Are you working through the #OReilly #book ‘Learning #Perl’? Get extra practice with co-author brian d foy’s ‘Learning Perl Exercises’ #ebook: https://leanpub.com/learning_perl_exercises
Don’t have ‘Learning Perl’ yet? Buy it in paperback or ebook here: https://shop.aer.io/oreilly/p/learning-perl-8th/9781492094951-9149
Prefer #Amazon #Kindle? https://amzn.to/3QZj7t6 (affiliate link)#books #bookstodon #coding #programming #SoftwareDevelopment #ProgrammingLanguages #Perl5 #RegularExpressions #regexes #regexps #Unicode #CPAN
-
@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: https://perldoc.perl.org/perlretut#Embedding-comments-and-modifiers-in-a-regular-expression
We format the rest of our code for humans. Why not #regexps?
#PerlCritic can warn against bad regexps: https://metacpan.org/search?size=200&q=module%3APerl%3A%3ACritic%3A%3APolicy%3A%3ARegularExpressions
-
@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. https://metacpan.org/pod/re::engine::RE2
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.