我有一根绳子
string = 'Ph no. : 999999999 | year: 2021 | class no.: 10Type: 2-A | S-no. : dfwef | Name : dfwf'
我想使用正则表达式python来提取类型。在这种情况下,我想要的输出是2-A
我已经试过了
import re
type = re.findall(r'Type: \d*-', string)
print(type)
我有多个这种类型的字符串,我想提取“type:”和“|”之间的代码文本
Tags:
使用regex
'(?<=Type: )[\w-]+'
(?<=Type: )
将在类型之后提取所有内容:[\w-]+
将只提取数字,单词和-如果
Type
只包含一个数字“-”和一个字母,那么这将为您提供所需的结果或者如果您只想提取2-A
最后,根据请求从
Type:
到|
提取任何文本,它将相关问题 更多 >
编程相关推荐