我正在开发一个程序,它可以获取如下字符串:
s = 'GPA: 3.4 GRE: 317 Round: Round 2 | West'
d = 'GPA: 3.7 GRE: 328 Round: Round 3 | Singapore'
a = 'GPA: undergrad: 3.68 grad: DPT 3.32 GMAT Waiver Round: Round 3'
c = 'GPA: 3.2 GMAT: 750 Round: Rolling Admissions | NY'
到目前为止,我只是使用重表达式获取轮数。 但对于像c这样的例外情况,我也需要让它返回“滚动录取”。有没有办法在圆形标志和管道标志之间获取数据
我一直在这样做:
R = re.findall('\S*Round ([a-zA-Z0-9]+)', d)
print(''.join(R))
下面的正则表达式获取两个delimter
Round:
和|
之间的值编辑: 注意,有几个实例中管道标志不可用。使用以下命令将搜索
Round:
之后和|
之前的字符串,或搜索到字符串的结尾您只需要获取第一个元素,这将是您请求的值
例如
给你
相关问题 更多 >
编程相关推荐