Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a regex expression that I tested on http://gskinner.com/RegExr/ and it worked, but when I used it in my C# application it failed.

My regex expression: (?<!d)d{6}Kd+(?=d{4}(?!d)) Text: 4000751111115425 Result: 111111

What is wrong with my regex expression?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.1k views
Welcome To Ask or Share your Answers For Others

1 Answer

This issue you are having is that .NET regular expressions do not support K, "discard what has been matched so far".

I believe your regex translates as "match any string of more than ten d digits, to as many digits as possible, and discard the first 6 and the last 4".

I believe that the .NET-compliant regex

(?<=d{6})d+(?=d{4})

achieves the same thing. Note that the negative lookahead/behind for no-more-ds is not necessary as the d+ is greedy - the engine already will try to match as many digits as possible.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...