RegExp实例方法:

1、Test()

 

RegExpObject.test(string)

判断string中是否有与表达式匹配的字符串,有则返回true,否则返回false

例如

var patt1=new RegExp("e");    

document.write(patt1.test("The best things in life are free"));   

由于该字符串中存在字母 "e",以上代码的输出将是:true

2、exec()

RegExpObject.exec(string)

exec() 方法检索字符串中的指定值。返回值是被找到的值。如果没有发现匹配,则返回 null。

例如

 
JScript 代码   复制
正则RegExp对象的用法正则RegExp对象的用法
var str= "cat2,hat8" ;
正则RegExp对象的用法
var reg=/c(at)\\d/ ;  有分组
正则RegExp对象的用法
console.info(reg.exec(str));//运行返回   ["cat2", "at"]
网址链接:http://www.studyofnet.com/news/662.html

相关文章:

  • 2022-12-23
  • 2021-05-23
  • 2022-12-23
  • 2021-12-10
  • 2017-12-06
  • 2022-12-23
猜你喜欢
  • 2021-04-21
  • 2021-11-30
  • 2021-09-29
  • 2021-10-04
  • 2021-06-05
  • 2021-06-03
  • 2021-10-03
相关资源
相似解决方案