4 ms·
What 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 te
by atoav 6y ago
What 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.