简体   繁体   English

如何编写 python 正则表达式来查找两个用斜线分隔的电话号码?

[英]How to write python regex to find two phone numbers with seprated by slash?

I have want to extract the phone number using regex.我想使用正则表达式提取电话号码。 i have phone series like 0097444603826,96824437746 and 0030693221591 / 0030693221550我有电话系列,例如 0097444603826,96824437746 和 0030693221591 / 0030693221550

my regex pattern = [-()\s\d]+?(?=\s*[+<]) everthing extracting but in last number 0030693221591 / 0030693221550 it is taking only second 0030693221550 i want help in writing regex like it should extract 0030693221591 / 0030693221550我的正则表达式模式 = [-()\s\d]+?(?=\s*[+<]) 一切都在提取,但在最后一个数字 0030693221591 / 0030693221550 中只需要第二个 0030693221550 我需要帮助编写正则表达式,就像它应该提取 0030693221591 / 0030693221550

import re

def main():
    data = 'i have phone series like 0097444603826,96824437746 and 0030693221591 / 0030693221550'
    match = re.findall('(\\d+\\s?[,/]\\s?\\d+)', data)
    for i in match:
        print(i)

if __name__ == '__main__':
    main()

() is a capture group (which is around the whole expression) ()是一个捕获组(围绕整个表达式)

\d+ 1 or more 0-9 \d+ 1 或更多 0-9

\s? 0 or 1 whitespace 0 或 1 个空格

[,/] either , or / [,/] , /

This returns:这将返回:

0097444603826,96824437746
0030693221591 / 0030693221550

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM