Sunday 15 August 2010

regex - python regular expression to remove repeated words -


I am a very new dragon

If there are repeated words, then I want to change the sentence.

Correct

  • The former "It's just too good" - & gt; "This is great"
  • Formerly "this is just" - & gt; "It is right now"

    I am currently using this reg. But there are so many changes on this letter. East. "My friend and I am happy" - & gt; "My friend and happy" (this removes "i" and space) error

      text = re.sub (r '(\ w +) \ 1', 'r' 1 'text) Duplicated words in the # line   

    How do I make the same change but check the words instead of the letters?

      text = re.sub (r '\ b (\ w +) (\ 1 \ B) + Duplicated words #remove   

    \ b in the line '+', r '\ 1', text) matches the empty string, but Only the beginning or the end of a word

    No comments:

    Post a Comment