Python regex match middle of string

前端 未结 1 376
遇见更好的自我
遇见更好的自我 2020-12-18 21:46

I have a python string, that I\'m trying to extract. I have a interesting issue:

>>> s=\"SKU 9780136058281, (ASIN B00A2KNZ2S, (binding Merchant: \'p         


        
1条回答
  •  佛祖请我去吃肉
    2020-12-18 22:13

    You need to use re.search and grouping,and Note that re.match match the pattern from beginning of the string :

    >>> s="SKU 9780136058281, (ASIN B00A2KNZ2S, (binding Merchant: 'paperback' / 'hardcover'))"
    >>> import re
    >>> re.search(r'SKU (\d+)',s).group(1)
    '9780136058281'
    

    r'SKU (\d+) will match any combination of digits (\d) with length 1 or more that came after SKU and a space!

    0 讨论(0)
提交回复
热议问题