Regular expressions of [Code] C # and js
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