Python: find a series of Chinese characters within a string and apply a function

前端 未结 4 1993
遥遥无期
遥遥无期 2021-01-14 06:55

I\'ve got a series of text that is mostly English, but contains some phrases with Chinese characters. Here\'s two examples:

s1 = \"You say: 你好. I say: 再見\"
s         


        
4条回答
  •  独厮守ぢ
    2021-01-14 07:29

    You could always use a in-place replace of the matched regular expression by using re.sub() in python.

    Try this:

    print(re.sub(r'([\u4e00-\u9fff]+)', translate('\g<0>'), utf_line))
    

提交回复
热议问题