3 ms·
And here I was thinking python was finally adding built-in, native, regex matching to the language, the one last reason I still use perl sometimes because of th
by ur-whale 6y ago
And here I was thinking python was finally adding built-in, native, regex matching to the language, the one last reason I still use perl sometimes because of the quasi java-level verbosity and heavy-handedness of the re python package.
But no, it's just about adding switch to python ... frankly, who cares.
- atoav 6y agoWhat do you mean with built-in native? Isn't `import re` kinda built-in? It is not an external dependency. So you could even run something like this from the terminal and get 1234 replaced by 2021: echo "1234foo" | python3 -c 'import re, sys; t=sys.stdin.read(); print(re.sub(r"(\d{4})", "2021", t))'
- SrslyJosh 6y agoI believe they mean adding a literal syntax specifically for regular expressions, ala perl and ruby, so you could write something like: print(/\d{4}/.sub("2021")) The backslash makes that example a little ugly, but maybe a delimiter other than "/" would work better. It's too bad that r"" is already taken for raw strings.
- nerdponx 6y agoCould be x"" for regeX or p"" for Pattern
- ur-whale 6y agoIn perl: print($1) if(/^hello (w[^d]+d)/); Do the same in python and pipe the code to wc -c Oh, and note the absence of any "import" statement or quotes in the perl code. Python is not has heavy-handed as C++ for regex parsing, but not by much.
- klmadfejno 6y agoThis was my train of thought as well. I think I'm ambivalent towards this. Handling different types of inputs like that is kind of fun. I don't really expect to need to know this one looking at coworkers code in the wild.