Regex for IBAN mask

后端 未结 4 1103
心在旅途
心在旅途 2021-01-22 05:18

I am trying to extract this text \"NL dd ABNA ffffdffffdffffd\" from string:

IBAN NL 91ABNA0417463300
IBAN NL91ABNA0417164300
Iban: NL 69 ABNA 402032566
4条回答
  •  广开言路
    2021-01-22 06:15

    You can use the following regex:

    (?i)(?:(?<=IBAN(?:[:\s]\s|\s[:\s]))NL\s?\d{2}\s?[A-Z]{4}[0 ]\s?\d{9,10})|(?:(?<=IBAN[:\s])NL\s?\d{2}\s?[A-Z]{4}[0 ]\s?\d{9,10})
    

    demo:

    https://regex101.com/r/zGDXa2/11

    If you work in python you can remove the (?:i) and replace it by a flag re.I or re.IGNORECASE

    Tested on:

    Uw BTW nummer NL80
     IBAN NL 11abna0317164300asdfasf234
    iBAN NL21ABNA0417134300 22
    Iban: NL 29 ABNA 401422366f sdf
    IBAN :NL 39 ABNA 0822416395s
    IBAN:NL 39 ABNA 0822416395s
    

    Extracts:

    NL 11abna0317164300
    NL21ABNA0417134300
    NL 29 ABNA 401422366
    NL 39 ABNA 0822416395
    NL 39 ABNA 0822416395
    

提交回复
热议问题