gpt4 book ai didi

Phone Number Matching with some Boundry Condition(带边界条件的电话号码匹配)

转载 作者:bug小助手 更新时间:2023-10-25 21:45:11 25 4
gpt4 key购买 nike



10 digit number starting with 6,7,8,9 or an 11 digit number starting with 0 or +91. The number has to be checked if it is present as a separate word (demarcated by spaces on both sides or space on side and a period/comma/newline on the other or a period/comma on both sides, or a period/comma on one side and newline on the other) and not part of any running text.

以6、7、8、9开头的10位数字或以0或+91开头的11位数字。必须检查数字是否作为单独的单词(由两侧的空格或两侧的空格和另一侧的句点/逗号/换行符或两侧的句点/逗号或一侧的句点/逗号和另一侧的换行符分隔),而不是任何连续文本的一部分。


(?:[,\s]|^)(\+91[6-9]\d{9}|[6-9]\d{9}|0[6-9]\d{9})


valid number 
with comma
8126131525,8126131526,08126131527,+918126131528

with space
8126131525 8126131526 08126131527 +918126131528

Examples it should match:

它应该匹配的示例:


8126131525,8126131526,08126131527,+918126131528 8126131525 8126131526 08126131527 +918126131528

Examples not to match :

不匹配的示例:


amit.81261215255
.81261315253
+9181261315258989
0812613152584
,+9181261315258989
81261215257.amit
amit@81261215255
06126131525@amit

I am new to regex

我是新来的regex


更多回答

re: 'checked if it is present as a separate word (demarcated by spaces on both sides or space on side and a period/comma/newline on the other or a period/comma on both sides, or a period/comma on one side and newline on the other' can you give some examples please

Re:检查它是作为一个单独的单词出现的(用两边的空格或两边的空格和另一边的句号/逗号/换行符,或者两边的句号/逗号,或者一边的句号/逗号和另一边的换行符来分隔)。你能举一些例子吗

valid number with comma 8126131525,8126131526,08126131527,+918126131528 without comma 8126131525 8126131526 08126131527 +918126131528

带逗号的有效数字8126131525、8126131526、08126131527、+918126131528不带逗号8126131525 8126131526 08126131527+918126131528

918126131528 has 12 digits. Maybe e.g. ^(?:(?:\+91\d|0\d|[6-9])\d{9}\b[., ]?)+\b$ - Please provide better description and examples of input/desired output, also mention your environment.

918126131528有12位数字。例如^(?:(?:91\d|0\d|[6-9])\d{9}\b[.,]?)+\b$-请提供更好的输入/所需输出的描述和示例,并提及您的环境。

@bobblebubble (?:[,\s]|^)(\+91[6-9]\d{9}|[6-9]\d{9}|0[6-9]\d{9}) this is my regex the problem is comming when i get +91812613152577 (invalid number because its length is more than 13 and still i am getting match upto 13 . I want to number to be string in that parameter length only .

@BOBBLEBLE泡泡(?:[,\S]|^)(\+91[6-9]\d{9}|[6-9]\d{9}|0[6-9]\d{9})这是我的正则表达式当我得到+91812613152577(无效的数字,因为它的长度超过13而我仍然匹配到13)时开始出现问题。我只想在该参数长度中将数字设为字符串。

@Amitsingh0823 I see you got it solved already by adding a \b word boundary after. If you want to shorten it a bit: (?:[,\s]|^)(?:\+91|0)?[6-9]\d{9}\b

@Amitsingh0823我看你已经解决了,只需在后面加上一个单词边界。如果想缩短一点:(?:[,\S]|^)(?:\+91|0)?[6-9]\d{9}\b

优秀答案推荐

Try this:

试试这个:


(?<!\w)(0\d|\+91|[6-9])\d{9}(?!\w)

See live demo.

观看现场演示。


The look arounds at each end are "not a word char", which matches end of input too.

每个结尾处的“Not a word char”,也与输入结尾处匹配。


This uses an alternation for +91 or a character in the range 6-9.

它使用+91的替代字符或6-9范围内的字符。



This work fine for me

这个对我来说很好


`(?:[,\s\.]|^)(\+91[6-9]\d{9}|[6-9]\d{9}|0[6-9]\d{9})\b`g


更多回答

not working fine a.8126131525 also matching .

不能正常工作。8126131525也匹配。

@Amitsingh0823 please explain in detail why 8126131525 should not match.

@Amitsingh0823请详细解释为什么8126131525不应该匹配。

Can you fix it for starting with zero also .

你能把它也从零开始修复吗?

@Amitsingh0823 OK - fixed for zero. I still don't understand why "a.8126131525" should not match.

@Amitsingh0823 OK-已修复为零。我还是不明白为什么“a.8126131525”不匹配。

It was matching . But early i didnt want dot and number .but later i changed .

这是匹配的。但最初我不想要点和数字。但后来我改变了。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com