Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

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.

"(?

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report