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

Regular expressions of [Code] C # and js

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

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

Metacharacters:

Single character:. []

Qualifier: * +? {n} {n,} {nrecom}

Head and tail: ^ $'

Other: | ()

Regular expressions are available in both js and C #.

In C #:

Create:

Var regex = new Regex ("\\ d")

Match:

Syntax: bool IsMatch (string input)

Var b = regex.IsMatch (str)

Replace:

Syntax: static string Replace (string input, string pattern, string replacement)

Var str = Regex.Replace (str, "\ d", "number")

Extract:

Syntax: MatchCollection Matches (string input)

Var mts = regex.Matches (str)

=

In JS:

Create:

Var regex = new RegExp ('\\ d');\\ need to escape remarks: iParticipate the case, match multiple lines, and match globally.

Var regex = /\ d bind; literal quantity does not need to be escaped

Match:

Boolean RegExp.test (string)

Var str = 'a1b1c1cards; var regex = /\ d str; alert (regex.test (str)); / / pop-up true to match to the number

Replace:

Var str = 'a1b1c1century; str.replace (/ (\ d). * (\ d) /,' $2jin1') result: a 1JI $1 and $2 represent the first and second matching results.

Extract:

Objs RegExp.exec (str) returns an array-like object

Var str = 'a1b1c1cards; var regex=/\ d str; var objs = regex.exec (str); result: objs [0] = 1

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

Network Security

Wechat

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

12
Report