In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail how to achieve the two regular replacement functions of JS and C#. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
The details are as follows:
Application example 1:
Pending string: str= "display=test name=mu display=temp"
Requirement: change all values after display= to localhost
JS processing method:
Str.replace (/ display=\ wigzag, "display=localhost")
C # processing method:
Regex reg=new Regex (@ "display=\ w *"); str=reg.Replace (str, "display=localhost")
Application example 2:
Pending string: str= "display=test name=mu display=temp"
Requirement: string becomes display=localhosttest name=mu display=localhosttemp
JS processing method:
Var reg = / (display=) (\ w*) / GTX var result;while ((result= reg.exec (str))! = null) {str= str.replace (result [0], result [1] + "localhost" + result [2]);}
C # processing method:
/ define the processing method / private string Evaluator (Match match) {/ / (display=) (\ w*) Groups is grouped according to the found strings / / Group 0 is the whole matching string, followed by string str = match.Groups [1] .value + "localhost" + match.Groups [2] .Value; return str } Regex regex = new Regex (@ "(display=) (\ w*)"); string result = regex.Replace (str, Evaluator)
Finally, there is a small regular summary of js:
The difference between string match and regular object exec
1. When the regular expression does not have / g, the two return the first matching string or string group (if there is a grouping in the regular)
2. When the regular expression has / g, match returns all matching string groups and ignores the grouping, while exec returns the first string or string group.
This is the end of this article on "how to achieve two regular replacement functions of JS and C#". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.