Overview
Regular expressions are used to retrieve and replace text that conforms to a pattern
Standard Regular Expression syntax
JavaScript support for regular expressions
Alternative notation
Reverse Surround
// requirement: Replace mpre.cnsuning.com to ${pre}, res.mpre.cnsuning.com not replace // implementation: JS does not support reverse loop sequence, using multiple matching " http://mpre.cnsuning.com/REShttp://res.mpre.cnsuning.com ". Replace (/[^\.) Mpre\.cnsuning/g,function ($1) { return $1. Replace (' mpre.cnsuning','${pre}')})
Named captures
Using index capture to circumvent
intersection and set difference set
// JS does not support intersection and set difference set, still can only use multiple matches // /[a-d[m-p]]/: can use ' | ' Alternative var reg =/[a-d]| [m-p]/; // intersection: [A-z&&[def]], the difference set is the same var reg1 =/([A-z])/,REG2 =/([def])/; var ' D ' && reg2.test (str);
Condition matching
Ditto, with multiple matches
JavaScript Basics-Regular Expressions