Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
elidepa368yfml, I just realised that naturally those won't cover any words at the beginning of sentences... any ideas how to do this in a cleaner way or should I just replace every possible contracted word one by one?
-
lotd77758yI think serializing to json will "escape" those..
Perhaps use str.replace to append backslash before the apostrophe? :p
Don't quote me on it though, I haven't worked much with python except for a few ncurses scripts.. :)
Btw, They'll doesn't actually do anything lol :D -
elidepa368y@DrEmann
Thanks for the word boundary tip! Now I use regexes like:
re.sub(r"\b(T|t)hey (re|ve|ll)\b", r"\1hey'\2", str)
and they work like a charm!
Much less code and the result is the same, even better! :) -
I personally would just escape all the apostrophes and double quotes and other special characters that may be lurking in the text.. Assuming this is going to be put into a database or something?
-
elidepa368y@turturtles
Actually it's the opposite. somebody has alredy put all those messages into db, and instead of just escaping the apostrophes as you should, he/she for some reason I just can't understand decided to completely replace them with spaces. Now my job is to retrieve that data and put all those apostrophes back. The database is not created by us, so I have no idea who's behind those spaces. -
r/badprogramming lol. I see someone mentioned regex, definitely the right route
Related Rants
So somebody decided that instead of simply escaping apostrophes it would be best to just delete them altogether. I m pretty sure you ll understand why that s a problem.
undefined
sql
apostrophes
python