Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

A string maybe this

ipath= "./data/NCDC/上海/虹桥/9705626661750dat.txt"

or this

ipath = './data/NCDC/ciampino/6240476818161dat.txt'

How do I know the first string contains chinese?

I find this answer maybe helpful: Find all Chinese text in a string using Python and Regex

but it didn't work out:

import re
ipath= "./data/NCDC/上海/虹桥/9705626661750dat.txt"
re.findall(ur'[u4e00-u9fff]+', ipath) # => []
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.4k views
Welcome To Ask or Share your Answers For Others

1 Answer

The matched string should be unicode as well

>>> import re
>>> ipath= u"./data/NCDC/上海/虹桥/9705626661750dat.txt"
>>> re.findall(r'[u4e00-u9fff]+', ipath)
[u'u4e0au6d77', u'u8679u6865']

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...