[英]How to search for a specific pattern in a string using regrex
I want to search for a specific pattern name
in the below string using regrex.我想使用正则表达式在下面的字符串中搜索特定的模式name
。 The name
occur after the selfie_
name
出现在自拍之后selfie_
for example:例如:
name = OKAH_AGHOLOR名称 = OKAH_AGHOLOR
url = 'https://ignite-api.s3.us-east-2.amazonaws.com/live/selfie_OKAH_AGHOLOR_22342028078-IND-1619350764067.jpeg'
I have tried the below regrex expression我试过下面的正则表达式
pattern = re.compile(r'_[A-Za-z_]+')
sequence = url
pattern.search(sequence).group()
output: output:
'_OKAH_AGHOLOR_'
Use lookarounds so the _
at the beginning and end are not included in the match.使用环视,使开头和结尾的_
不包含在匹配中。
pattern = re.compile(r'(?<=_)[a-z_]+(?=_)', re.IGNORECASE)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.