[英]Extract substring using regular expressions
我需要只提取部分0000520621
從字符串nmg-22373-0000520621-001-010000520621
。
我想在python
使用正則表達式執行此任務。
你能幫我嗎?
my_string = 'nmg-22373-0000520621-001-010000520621'
expected = re.search('22373-(.+?)-001',l)
if expected:
print expected.group(1)
您不需要正則表達式即可獲得列表的第三個成員。 只需將字符串除以減號,然后選擇它的第三位成員即可。
test = 'nmg-22373-0000520621-001-010000520621'
test.split('-')[2]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.