Cut & Paste String-In to try out examples ## 01-16:
String-In = abc123!@#DEF456$%^
## RegEx String-Out (comments)
01 /\d/ "1" 02 /\D/ "a" 03 /\d+/ "123" (+ gives multiple chars. of first occurence) 04 /\D+/ "abc"
05 /\d/g "1", "2", "3", "4", "5", "6" (elements of an array) 06 /\D/g "a", "b", "c", "!", "@", "#", "D", "E", "F", "$", "%", "^" 07 /\d+/g "123", "456" 08 /\D+/g "abc", "!@#DEF" "$%^"
09 /\w/ "a" 10 /\W/ "!" 11 /\w+/ "abc123" 12 /\W+/ "!@#"
13 /\w/g "a", "b", "c", "1", "2", "3", "D", "E", "F", "4", "5", "6" 14 /\W/g "!", "@", "#", "$", "%", "^" 15 /\w+/g "abc123", "DEF456" 16 /\W+/g "!@#", "$%^"
Next, try these four: \s = Matches any Single character of white space \S = Matches any Single character Non white space \b = Matches word boundaries \B = Matches Non-Word boundaries
Cut & Paste String-In to try out examples ## 17-32:
String-In = This is a very short sentence.
## RegEx String-Out (comments)
17 /\s/ " " (white space) 18 /\S/ "T" 19 /\s+/ " " 20 /\S+/ "This"
21 /\s/g " ", " ", " ", " ", " " (5 white spaces) 22 /\S/g "T", "h", "i", "s", "i", "s", "a", "v", "e", "r", ... 23 /\s+/g " ", " ", " ", " ", " " 24 /\S+/g "This", "is", "a", "very", "short", "sentence."
25 /\b/ "" (null, empty string) 26 /\B/ "" 27 /\b+/ null (empty string) 28 /\B+/ null
29 /\b/g "", "", "", "", "", "", "", "", "", "", "", "" 30 /\B/g "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" 31 /\b+/g null 32 /\B+/g null
Have fun!