Alternative of re library in Python

  python, re

I have a code portion where i imported re library. Here is my code:

import re
def clean_text(txt):
  txt = txt.lower()
  txt = re.sub(r"i'm", "i am", txt)
  txt = re.sub(r"he's", "he is", txt)
  txt = re.sub(r"she's", "she is", txt)
  txt = re.sub(r"that's", "that is", txt)
  txt = re.sub(r"[^ws]", "", txt)
  return txt

I need a different method to pre-process the string text. The method can be manual or a library of python.

Source: Python Questions

LEAVE A COMMENT