【问题标题】:How to write a regular expression to extract the account number from the bank passbook?如何编写正则表达式从银行存折中提取帐号?
【发布时间】:2020-04-02 21:16:55
【问题描述】:

如果我的列表包含帐号并且我的列表包含帐号,我需要一个正则表达式来提取号码。我尝试过这样的事情。

def check(extracted_text, words): 

    for word in str(extracted_text):
        string_list = word.split()
        word1 , word2, word3 = words
        if (word1 in string_list) and ((word2 in string_list) or (word3 in string_list)):
            print(string_list)

words = ['Account','Number','No'] 
print(check(extracted_text, words)) 

【问题讨论】:

  • 您能否添加带有帐号的文本示例以及带有非帐号数字的文本?
  • 你试过了,结果如何?您当前的尝试如何无法满足您的需求?

标签: python regex python-2.7


【解决方案1】:

你可以试试下面的方法,

import re

def check(extracted_text, words):
    for line in extracted_text:
        if re.search("^Account\s+(Number|No)+.*$", line):
                return (line)

有关正则表达式的更多参考, https://www.w3schools.com/python/python_regex.asp

【讨论】:

  • 谢谢。但它只适用于一种情况。我将在此处包含我提取的文本,以便您清楚了解我的需求。我的文字是这样的。我只需要帐号和帐号。 '银行','ROYAPURAM(94','151,Mannarsamy Koil St.','yapuram','Chennal','电话号码:25951427','IFSC 代码:ID33535300343','इंडियन बैंक','印度银行' , 'Your Tech-Friendly Bana', 'CIE :3061895793', 'Name : M AMULU', 'Account No : 6057514202', 'Address', ': OLD NO.127 NO.427', 'CHENNAI']跨度>
  • 不需要正则表达式。没有它本身,如果有人知道,请尽快告诉我。非常感谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-03-04
  • 1970-01-01
  • 2023-03-28
  • 1970-01-01
相关资源
最近更新 更多