如何在C#中使用正则表达式匹配模式 [英] How to match Pattern using Regex in C#
问题描述
我希望模式开始与 9838/9839/9918/9919
然后是这些模式(这些是手机号码)
起始数字如9839和最后6位数字如下图案
XXYYAB AXXYYZ AXYZ00 AXXXYZ ABXXYY AXYYYZ AXXXXY
337719 733119 912300 522238 295588 257772 488886
我使用正则表达式 9839([0-9])\ 1 {3}
此正则表达式匹配9839AXXXXZ,但它也返回5倍匹配的数字,如9839555559
例如手机号码 -
9839337719-XXYYAB
9839733119-AXXYYZ
9839912300 -AXYZ00
9839522238-AXXXYZ
9839295588-ABXXYY
9839257772-AXYYYZ
9839488886-AXXXXY
我卡住了请帮帮我们
提前谢谢
I want to match Patterns Starts With 9838/9839/9918/9919
and followed by these patterns(these are mobile numbers)
starting digits like 9839 and last 6 digits like below patterns
XXYYAB AXXYYZ AXYZ00 AXXXYZ ABXXYY AXYYYZ AXXXXY
337719 733119 912300 522238 295588 257772 488886
I used Regular Expression 9839([0-9])\1{3}
this regex matching 9839AXXXXZ but it also returning 5 times matched digits like 9839555559
For Example Mobile Numbers-
9839337719-XXYYAB
9839733119-AXXYYZ
9839912300-AXYZ00
9839522238-AXXXYZ
9839295588-ABXXYY
9839257772-AXYYYZ
9839488886-AXXXXY
I'm stuck please help me out guys
thanks in advance
推荐答案
As我理解你好l,正则表达式模式应如下所示: ^(9838 | 9839 | 9918 | 9919)\d {6} \-\w {6}
As per i understand you well, the regex pattern should look like: ^(9838|9839|9918|9919)\d{6}\-\w{6}
* 将mulitline选项设置为true。
我测试了它:
* with mulitline option set to true.
I tested it on:
9839337719-XXYYAB
9839733119-AXXYYZ
9839912300-AXYZ00
9838488886-AUXXXU
9839522238-AXXXYZ
9839295588-ABXXYY
9949488886-AUXXXY
9839257772-AXYYYZ
9839488886-AXXXXY
9859488886-AXXXXY
它返回8条满足标准的记录(最后一条被忽略)。
It returns 8 records fulfilling criteria (the last one is ignored).
这篇关于如何在C#中使用正则表达式匹配模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!