15
elidepa
8y

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.

Comments
  • 2
    fml, 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?
  • 0
  • 4
    Look up regexes, specifically the word boundary metacharacter.
  • 0
    I 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
  • 0
    What about typos?... Man that must have been a quick fix...
  • 1
    @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! :)
  • 2
    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?
  • 0
    @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.
  • 0
    r/badprogramming lol. I see someone mentioned regex, definitely the right route
Add Comment