Python Regular Expression Matching: ## ##

前端 未结 7 863
后悔当初
后悔当初 2021-01-25 23:31

I\'m searching a file line by line for the occurrence of ##random_string##. It works except for the case of multiple #...

pattern=\'##(.*?)##\'
prog=re.compile(p         


        
7条回答
  •  后悔当初
    2021-01-25 23:44

    >>> import re
    >>> text= 'lala ###hey## there'
    >>> matcher= re.compile(r"##[^#]+##")
    >>> print matcher.sub("FOUND", text)
    lala #FOUND there
    >>>
    

提交回复
热议问题