如何0
从行K'0
中捕获要捕获的其他所有内容。
这是我的正则表达式示例
这是我的正则表达式
K'(?P<name1>81|61|64|44|86|678|41|49|33|685|1(?:33|45)?|\d{1,3})?\d+
K'0 <<<----adding the ? here |\d{1,3})?\d+ as want to pick up if there is only
K'93 <<<--- 1 number 2 number or 3 numbers (ie. K'0, K'93, K'935 )
K'935
K'8134567
K'81345678
K'6134516789
K'61345678
K'643456
K'646345678
K'1234567890
K'12345678901
K'1454567890 <<<--- want 145 returned and not 1
K'13345678901 <<<--- want 133 returned and not 1
K'3214567890123
K'32134567890123
K'3654567890123
K'8934567890123
K'6554567890123
I am interested in the digits after K'
I am looking to do this using regex but not sure if it can be done. What I want is:
if the number starts with 81 return 81
if the number starts with 61 return 61
...
if the number starts with something i am not interested in return other(or its first digits of 1-3)
The above criteria works:
but what I also want is:
if the fist digit is 1 then return 1 BUT
if the fist digit is 1 and the 2nd and 3rd digit are 45 return 145 and don't return just 1
if the fist digit is 1 and the 2nd and 3rd digit are 33 return 133 and don't return just 1
I presume I have to put something inside this part of the regex |(1)\d+|
Questions:
Does regex sort the data first?
Is the order of the regex search important to how it is implemented? i deally I do not want this.
您可以将正则表达式更改为:
K'(?P<name1>0|81|61|64|44|86|678|41|49|33|685|1(?:33|45)?|\d{1,3})?\d*
notice -----^ and also --^
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句