Python, Regular Expression Postcode search

前端 未结 3 935
名媛妹妹
名媛妹妹 2021-01-03 06:54

I am trying to use regular expressions to find a UK postcode within a string.

I have got the regular expression working inside RegexBuddy, see below:



        
3条回答
  •  一向
    一向 (楼主)
    2021-01-03 07:46

    Try

    import re
    re.findall("[A-Z]{1,2}[0-9][A-Z0-9]? [0-9][ABD-HJLNP-UW-Z]{2}", x)
    

    You don't need the \b.

提交回复
热议问题