Split string with multiple-character delimiter

前端 未结 3 583
慢半拍i
慢半拍i 2020-12-01 23:47

say I have the following string:

"Hello there. My name is Fred. I am 25.5 years old."

I want to split this into sentences, so that

相关标签:
3条回答
  • 2020-12-02 00:09

    Works for me

    >>> "Hello there. My name is Fr.ed. I am 25.5 years old.".split(". ")
    ['Hello there', 'My name is Fr.ed', 'I am 25.5 years old.']
    
    0 讨论(0)
  • 2020-12-02 00:10

    You can use split function in regular expression library :

    import re
    re.split('\. ', "Hello there. My name is Fred. I am 25.5 years old.")
    
    0 讨论(0)
  • 2020-12-02 00:12
    >>> "Hello there. My name is Fred. I am 25.5 years old.".rstrip(".").split(". ")
    ['Hello there', 'My name is Fred', 'I am 25.5 years old']
    
    0 讨论(0)
提交回复
热议问题