Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

An example Analysis of looking around in reverse order of regular expression matching principle

Shulou Source: shulou.com Published: 2022-06-01 06:51:01 09月13日 Update

This article mainly shows you the "example analysis of the reverse order look around the regular expression matching principle". The content is simple and clear. I hope it can help you solve your doubts. Let the editor lead you to study and learn the "example analysis of the reverse order look around the regular expression matching principle".

Explanation: some of the contents need to be further studied and revised, because the recent work is too busy to find time for the time being, those who have not studied can skip this article, and those who want to study should not be influenced by my train of thought. If there is a clear study, please correct the first question.

I encountered this problem in the CSDN forum the other day:

Var str= "8912341253789"

The duplicate number in this string needs to be removed, which is the result 89123457.

First of all, it is important to note that this requirement is not suitable to be implemented with regularities, at least, regularities are not the best way to implement them.

This problem itself is not the focus of this paper, and what this paper is going to discuss is another problem of regular matching principle, which is mainly caused by the solution to this problem.

First take a look at the solution to the problem itself.

The code is as follows:

String str = "8912341253789"

Regex reg = new Regex (@ "((\ d)\ dink?)\ 2")

While (str! = (str = reg.Replace (str, "$1")) {}

RichTextBox2.Text = str

/ *-output-

89123457

, /

Based on this, another question raised by a friend is why the use of the following rules has no effect.

"(?

Tags: Expression position regular success character control control attempt string process content result greed pattern reverse state drive length round principle Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Shulou Technology Xiaomi NVidia Shulou Tech Info