0

I have the second sentence:

blablabla.blabla

and I would like the final sentence to be without the punctuation and without what comes after the period, like this:

blablabla

I made the following code, I used Regex, but the end result is not the expected one, does anyone know what may be wrong in the code?

import re
from re import sub

stringTEXT = "blablabla.blabla"
stringTEXT = re.sub(r'..*', '',stringTEXT )
simonica
  • 107
  • 1
  • 9
  • `.` is a special char, you need to escape it to match a literal dot. – Wiktor Stribiżew May 04 '20 at 16:59
  • The easiest solution is to match the regular expression `[^.]*`. That will match zero or more characters from the beginning of the string (no need for `^` before `[^.]*`) that are not dots. It therefore will match characters until the next is a dot or it reaches the end of the string. Note that a dot need not be escaped when it is in a character class. Think about it: it would pointless if a dot in a character class were interpreted as any character. `[.abc]` would be the same as `[.]` which would be the same as `.`. – Cary Swoveland May 04 '20 at 17:23

0 Answers0