Python regex — extraneous matchings

后端 未结 5 1274
执念已碎
执念已碎 2021-01-18 07:17

I want to split a string using -, +=, ==, =, +, and white-space as delimiters. I want to keep the delimiter

5条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-18 08:14

    Perhaps re.findall would be more suitable for you?

    >>> re.findall(r'-|\+=|==|=|\+|[^-+=\s]+', "hello-+==== =+  there")
    ['hello', '-', '+=', '==', '=', '=', '+', 'there']
    

提交回复
热议问题