国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

java - regular expression problem
ringa_lee
ringa_lee 2017-06-14 10:53:06
0
1
1036

I want to use regular expressions to extract the following information. How to write it?

123 男 北京          張三
343 女 河北 石家莊   李四
2343 男 山東         王五



提取 男 張三
     女 李四
     男 王五
ringa_lee
ringa_lee

ringa_lee

reply all(1)
洪濤

In fact, for Chinese, especially Chinese in this format, I don’t recommend using regular expressions, although it can be achieved with difficulty:

# coding: utf8
import re
filename = '2.txt'
patern = re.compile(r'^\d+ (\S+).*?(\S+)')
with open(filename) as f:
    for i in f:
        result = patern.findall(i[:-1])
    
        if result and len(result[0]) == 2:
            print result[0][0], result[0][1]
            
# 輸出:
男 北京
女 河北
男 山東

You can also use the split method (suggestion):

# coding: utf8
filename = '2.txt'
with open(filename) as f:
    for i in f:
        result = i.split()
        print result[1], result[-1]
    
# 輸出:
男 北京
女 河北
男 山東
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template