http://zhangyanyansy.blog.163.com/blog/static/135305097201042110756638/
Basic knowledge of JavaScript regular expressions
1 JavaScript regular object creation and usage declaration JavaScript regular Expressions
var recat = new RegExp ("cat");
You can also
var recat =/cat/; Perl Style (recommended)
2 learning the most commonly used test exec match search replace split 6 methods
1 Test checks to see if the specified string exists
var data = "123123″;"
var recat =/123/gi;
Alert (recat.test (data)); Tr
Check to see if the character is present G continue to go down I case insensitive
2 Exec return query value
var data = "123123,213,12312,312,3,cat,cat,dsfsdfs,";
var recat =/cat/i;
Alert (recat.exec (data)); Cat
3 Match Gets the query array
var data = "123123,213,12312,312,3,cat,cat,dsfsdfs,";
var recat =/cat/gi;
var arrmactches = Data.match (recat)
for (Var i=0;i < arrmactches.length; i++)
{
Alert (Arrmactches[i]); Cat Cat
}
4 Search to return to a location similar to IndexOf
var data = "123123,213,12312,312,3,cat,cat,dsfsdfs,";
var recat =/cat/gi;
Alert (Data.search (Recat)); 23
5 Replace replacement character using regular substitution
var data = "123123,213,12312,312,3,cat,cat,dsfsdfs,";
var recat =/cat/gi;
Alert (Data.replace (Recat, "libinqq"));
6) split using a regular split array
var data = "123123,213,12312,312,3,cat,cat,dsfsdfs,";
var recat =/\,/;
var arrdata = Data.split (recat);
for (var i = 0; i < arrdata.length; i++)
{
Alert (Arrdata[i]);
}
3 Learning under the simple class negative class range class combination class
Simple class
var data = "1LIBINQQ,2LIBINQQ,3LIBINQQ,4LIBINQQ";
var recat =/[123]libinqq/gi;
var arrdata = Data.match (recat);
for (var i = 0; i < arrdata.length; i++)
{
Alert (Arrdata[i]); 1LIBINQQ 2LIBINQQ 3LIBINQQ
}
Negative to Class
var data = "ALIBINQQ,1LIBINQQ,2LIBINQQ,3LIBINQQ,4LIBINQQ"; \ 拏
var recat =/[^a123]libinqq/gi;
var arrdata = Data.match (recat);
for (var i = 0; i < arrdata.length; i++)
{
Alert (Arrdata[i]); 4libinqq
}
Scope class
var data = "Libinqq1,libinqq2,libinqq3,libinqq4,libinqq5″;" \ 拏
var recat =/libinqq[2-3]/gi;
var arrdata = Data.match (recat);
for (var i = 0; i < arrdata.length; i++)
{
Alert (Arrdata[i]); LIBINQQ2 libinqq3
}
Combination Class
var data = "A,b,c,w,1,2,3,5″;" \ 拏
var recat =/[a-q1-4\n]/gi;
var arrdata = Data.match (recat);
for (var i = 0; i < arrdata.length; i++)
{
Alert (Arrdata[i]); A b C 1 2 3
}
These are JS is the most basic method of use.
Second, the jqry regular expression processing
1.test method
reg=/^\w{3,}@\w+ (\.\w+) +$/; |
3 |
$ ("#test"). HTML ("<b> Please enter the correct email address </b>"); |
2.exec method
$.formatdate.patternparts =/^ (yy (yy)? | M (m (m)?)? | D (d)? | EEE (E)? | a| H (h)? | H (h)? | M (m)? | s (s)? | S)/; |
2 |
var matched = $.formatdate.patternparts.exec (pattern); |
4 |
Null if conforming to matched array index:0 |
5 |
Result.push (this,date) ($.formatdate.patternval[matched[0]].call); |
6 |
Pattern = Pattern.slice (matched[0].length); |