本文介绍了使用 Python 从文本中提取 IBAN的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我想用 Python 从文本中提取 IBAN 号码.这里的挑战是,IBAN 本身可以用多种方式编写,数字之间有空格,我发现很难将其转换为有用的正则表达式模式.

I want to extract IBAN numbers from text with Python. The challenge here is, that the IBAN itself can be written in so many ways with spaces bewteen the numbers, that I find it difficult to translate this in a usefull regex pattern.

我编写了一个 演示版,它试图从文本中匹配所有德国和奥地利的 IBAN 号码.

I have written a demo version which tries to match all German and Austrian IBAN numbers from text.

^DE([0-9a-zA-Z]\s?){20}$

我在stackoverflow上看到过类似的问题.但是,将 IBAN 数字的不同书写方式与文本中提取这些数字的方式相结合,使我的问题很难解决.

I have seen similar questions on stackoverflow. However, the combination of different ways to write IBAN numbers and also extracting these numbers from text, makes it very difficult to solve my problem.

希望你能帮我解决这个问题!

Hope you can help me with that!

推荐答案

可以使用

\b(?:DE|AT)(?:\s?[0-9a-zA-Z]){18}(?:(?:\s?[0-9a-zA-Z]){2})?\b

查看正则表达式演示.详情:

  • \b - 词边界
  • (?:DE|AT) - DEAT
  • (?:\s?[0-9a-zA-Z]){18} - 出现 18 次可选空格和字母数字字符
  • (?:(?:\s?[0-9a-zA-Z]){2})? - 可选空格和字母数字字符的两个序列的可选出现
  • \b - 词边界.
  • \b - word boundary
  • (?:DE|AT) - DE or AT
  • (?:\s?[0-9a-zA-Z]){18} - eighteen occurrences of an optional whitespace and then an alphanumeric char
  • (?:(?:\s?[0-9a-zA-Z]){2})? - an optional occurrence of two sequences of an optional whitespace and an alphanumeric char
  • \b - word boundary.

这篇关于使用 Python 从文本中提取 IBAN的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-09 00:51