Metacharacters
Single character:. []
Qualifier: * +? {n} {N,} {n,m}
Tail: ^ $ '
Other: | ()
Regular expressions are available in both JS and C #.
In C #:
Create:
var regex = new Regex ("\\d");
The:
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");
Extraction:
Syntax: MatchCollection Matches (String input)
var mts = regex. Matches (str);
===========================================================================
JS in:
Create:
var regex = new RegExp (' \\d '); \ \ Need to escape note: I,m,g for ignoring case, matching multiple lines, global matching
var regex =/\d/; Literal methods do not need to be escaped
The:
Boolean regexp.test (String);
var str = ' A1B1C1 '; var regex =/\d/; Alert (Regex.test (str)); Popup true, match to number
Replace:
var str = ' A1B1C1 '; Str.replace (/(\d). * (\d)/, ' $2,$1 ') results: a1,1 $ and $ $ represent the first and second results matched to each other.
Extraction:
Objs regexp.exec (str) returns an array-like object
var str = ' A1B1C1 '; var regex=/\d/; var objs = regex.exec (str); Result: objs[0] = 1
[Code] Regular expressions for C # and JS