var str = "Thisis my data for reg Express for test data in javascript";
var reg = /(d)ata/;
var regg = /(d)ata/g;
//match();
console.log( str.match( reg ) );
/*["data", "d", index: 11, input: "This is mydata for reg Express for test data in javascript"] */
console.log( str.match( regg ) );
/*["data", "data"]*/
//match的表达式匹配了全局标记g将出现所有匹配项,但所有匹配中不会包含子匹配项。
//search 方法返回与正则表达式查找内容匹配的第一个子字符串的位置(偏移位)。 说明:如果找到则返回子字符至开始处的偏移位,否则返回-1。
console.log( str.search(reg) );
/* 11 */
//eplace 方法返回根据正则表达式进行文字替换后的字符串的复制
console.log( str.replace(reg,"***") );
/* This is my *** for reg Express for test data in javascript */
console.log( str.replace(regg,"***") );
/* This is my *** for reg Express for test *** in javascript */
//split 方法将一个字符串分割为子字符串,然后将结果作为字符串数组返回。
console.log( str.split(reg) );
console.log( str.split(regg) );
/*["This is my ", "d", " for regExpress for test ", "d", " in javascript"] */
// exec();
//console.log( reg.exec( str ) );
//console.log( regg.exec( str ) );
/* ["data", "d", index: 11, input:"This is my data for reg Express for test data in javascript"] */
var arr = null;
while( (arr = regg.exec(str ))!=null ){
console.log(arr );
}
/*
["data", "d", index: 11,input: "This is my data for reg Express for test data in javascript"]reg.js:29
["data", "d", index: 41,input: "This is my data for reg Express for test data in javascript"]
*/
//test 方法检查字符串是否与给出的正则表达式模式相匹配,如果是则返回 true,否则就返回 false
console.log( reg.test( str ) );
/* true */
//总结针对javascrpt来说 对于reg正则的函数 test(),exec()
//对于字符串来说 match(),search(),replace(),split()
//主要使用 split(),replace(),match()
var str = "Thisis my data for reg Express for test data in javascript";
var reg = /(d)ata/;
var regg = /(d)ata/g;
//match();
console.log( str.match( reg ) );
/*["data", "d", index: 11, input: "This is mydata for reg Express for test data in javascript"] */
console.log( str.match( regg ) );
/*["data", "data"]*/
//match的表达式匹配了全局标记g将出现所有匹配项,但所有匹配中不会包含子匹配项。
//search 方法返回与正则表达式查找内容匹配的第一个子字符串的位置(偏移位)。 说明:如果找到则返回子字符至开始处的偏移位,否则返回-1。
console.log( str.search(reg) );
/* 11 */
//eplace 方法返回根据正则表达式进行文字替换后的字符串的复制
console.log( str.replace(reg,"***") );
/* This is my *** for reg Express for test data in javascript */
console.log( str.replace(regg,"***") );
/* This is my *** for reg Express for test *** in javascript */
//split 方法将一个字符串分割为子字符串,然后将结果作为字符串数组返回。
console.log( str.split(reg) );
console.log( str.split(regg) );
/*["This is my ", "d", " for regExpress for test ", "d", " in javascript"] */
// exec();
//console.log( reg.exec( str ) );
//console.log( regg.exec( str ) );
/* ["data", "d", index: 11, input:"This is my data for reg Express for test data in javascript"] */
var arr = null;
while( (arr = regg.exec(str ))!=null ){
console.log(arr );
}
/*
["data", "d", index: 11,input: "This is my data for reg Express for test data in javascript"]reg.js:29
["data", "d", index: 41,input: "This is my data for reg Express for test data in javascript"]
*/
//test 方法检查字符串是否与给出的正则表达式模式相匹配,如果是则返回 true,否则就返回 false
console.log( reg.test( str ) );
/* true */
//总结针对javascrpt来说 对于reg正则的函数 test(),exec()
//对于字符串来说 match(),search(),replace(),split()
//主要使用 split(),replace(),match()