Divide string by line break or period with Python regular expressions

后端 未结 5 1249
逝去的感伤
逝去的感伤 2020-12-17 10:31

I have a string:

\"\"\"Hello. It\'s good to meet you.
My name is Bob.\"\"\"

I\'m trying to find the best way to split this into a list divi

5条回答
  •  天涯浪人
    2020-12-17 11:18

    >>> s = """Hello. It's good to meet you.
    ... My name is Bob."""
    >>> import re
    >>> p = re.compile(r'[^\s\.][^\.\n]+')
    >>> p.findall(s)
    ['Hello', "It's good to meet you", 'My name is Bob']
    >>> s = "Hello. #It's good to meet you # .'"
    >>> p.findall(s)
    ['Hello', "#It's good to meet you # "]
    

提交回复
热议问题