如何从Python中的类似字符串中获取值?

Dim*_*kas 2 python regex expression

假设我有一个包含类似字符串的文件中的以下字符串:

Andorra la Vella|ad|Andorra la Vella|20430|42.51|1.51|
Canillo|ad|Canillo|3292|42.57|1.6|
Encamp|ad|Encamp|11224|42.54|1.57|
La Massana|ad|La Massana|7211|42.55|1.51|
...
Run Code Online (Sandbox Code Playgroud)

如何使用正则表达式打印第一个数字(或每个字符串的第四个字段)?而且,如果第四个数字超过10000,我怎么能打印特定线的前4个字段(例如"Andorra la Vella""ad""Andorra la Vella"20430)?

unu*_*tbu 5

我认为csv在这种情况下使用模块会更容易:

import csv
with open(filename, 'rb') as f:
    for row in csv.reader(f, delimiter='|'):
        num = float(row[3])
        if num > 10000:
            print(row[:4])
Run Code Online (Sandbox Code Playgroud)