btwael / superstring.py

A fast and memory-optimized string library for heavy-text manipulation in Python
MIT License
250 stars 11 forks source link

Feature request: replace #1

Open endrebak opened 4 years ago

endrebak commented 4 years ago
>>> "hi".replace("h", "H")
Hi

Would be neat if it could take a dict so this worked:

>>> "hi".replace({"h": "i", "i": "h"})
ih

Or a regex (see pandas.Series.str for inspiration?):

"hi".replace("h|i", "NYAN")
NYANNYAN
btwael commented 4 years ago

Hello @endrebak, thank you, I will start working on this for the as soon as possible. I will check also that pandas.Series.str.

kamikaze commented 4 years ago

pervert request... how about sticking to standard string api and implementing extra stuff in a separate class/whatever? And creating a PR for Python to include your optimizations for standard string

endrebak commented 4 years ago

Or the PR could improve the API too if it is backwards compatible. The second suggestion is but the third isn’t.

This is backwards compatible:

import re
pat = re.compile(“h|i”)
"hi".replace(pat, "NYAN")
NYANNYAN