| Sign | Description |
|---|---|
| \w | [a-Z] and [0-9] and _ |
| \s | All kind of whitespaces |
| \n, \r, \t | Carriage Return, Tab, Line Break |
| \d | Decimals |
| \p{} | All kind of signs with property X |
| \W | ~\w |
| \S | ~\s |
| \D | ~\D |
| \P{} | ~\p{} |
| . | Everything except \n |
^ | Beginning of line |
| $ | End of line |
/Regular Expression/g → Global matching, do not stop after first match
/Regular Expression/i → Case insensitive
| Sign | Description |
|---|---|
| ? | {0,1} |
| + | {1,} |
| * | {0,} |
| {n} | n signs |
| {n,} | n or more signs |
| {,m} | at most m signs |
| {n,m} | between n and m signs |
Working with two groups:
'http://www.google.ch'.replace(/(http:\/\/(\S*))/g, '<a href=“$1”>$2<\/a>');
→ ”<a href=“http://www.google.ch”>www.google.ch</a>”
Non matching group start with ?:
'http://www.google.ch'.replace(/(?:http:\/\/(\S*))/g, '<a href=“$1”>$2<\/a>');
→ ”<a href=“www.google.ch”>$2</a>”
'%aa%bb%c%'.match(/\w{2,}/) → [“aa”]
'%aa%bb%c%'.match(/\w{2,}/g) → [“aa”, “bb”]
'Hallo+Fan'.match(/\++/); → [”+”]
'ab%07cd%1Bef%0Aghi%00jk'.replace(/%[01][a-f\d]?/gi,””); → 'abcdefghijk' (to remove ascii-characters in the range %00 to %20)
'http://www.google.ch'.replace(/(http:\/\/\S*)/g, '<a href=“$1”>$1<\/a>') → ”<a href=“http://www.google.ch”>http://www.google.ch</a>”