RE match fail in python, confuse with the result on regex101

后端 未结 2 853
攒了一身酷
攒了一身酷 2021-01-25 10:02

http://regex101.com/r/oU6eI5/1 , test here seam works, but when i put in Python, match whole str.

str = galley/files/tew/tewt/tweqt/
re.sub(\'^.+/+([^/]+/$)\', \         


        
2条回答
  •  死守一世寂寞
    2021-01-25 10:15

    It would be better if you define the pattern or regex as raw string.

    >>> import re
    >>> s = "galley/files/tew/tewt/tweqt/"
    >>> m = re.sub(r'^.+/+([^/]+/$)', r'\1', s)
                   ^                  ^
    >>> m
    'tweqt/'
    

提交回复
热议问题