惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Simon Willison's Weblog
Simon Willison's Weblog
G
Google Developers Blog
Spread Privacy
Spread Privacy
I
InfoQ
V
V2EX
S
Schneier on Security
小众软件
小众软件
C
CERT Recently Published Vulnerability Notes
博客园 - 聂微东
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Stack Overflow Blog
Stack Overflow Blog
T
Threat Research - Cisco Blogs
L
Lohrmann on Cybersecurity
Recent Announcements
Recent Announcements
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Attack and Defense Labs
Attack and Defense Labs
云风的 BLOG
云风的 BLOG
The Hacker News
The Hacker News
S
SegmentFault 最新的问题
C
Cybersecurity and Infrastructure Security Agency CISA
NISL@THU
NISL@THU
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
GbyAI
GbyAI
Latest news
Latest news
S
Secure Thoughts
Project Zero
Project Zero
MongoDB | Blog
MongoDB | Blog
I
Intezer
Security Latest
Security Latest
Apple Machine Learning Research
Apple Machine Learning Research
Vercel News
Vercel News
N
Netflix TechBlog - Medium
V2EX - 技术
V2EX - 技术
量子位
T
Threatpost
T
The Blog of Author Tim Ferriss
Y
Y Combinator Blog
T
Tor Project blog
A
Arctic Wolf
Microsoft Security Blog
Microsoft Security Blog
T
The Exploit Database - CXSecurity.com
大猫的无限游戏
大猫的无限游戏
T
Tailwind CSS Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
C
Check Point Blog
博客园 - Franky
Google DeepMind News
Google DeepMind News
The Register - Security
The Register - Security
The GitHub Blog
The GitHub Blog
L
LINUX DO - 热门话题

博客园 - 溶入海洋中的雨滴

ADO Entities Framework不对多表查询进行优化? case when遇上null值 【转】C#正则表达式整理备忘 【摘】UI设计中对比色颜色的选取 JavaScript中的正则表达式解析 用js实现用回车键、ctrl键在文本框导航 [原]无刷新三级连动用户控件 c#批量插入数据到数据库【支持事务操作】 SQL:定时作业的设置方法 【转】c#用柱形图、折线图和饼形图展示数据 【原】css设置布局时,尽量天上背景色 【原】JS控制控件的显示,你选择display还是visibilty 【原】js实现2个listbox的乾坤大挪移 [转]数据库设计14个技巧 【转】sql查询性能调试,用SET STATISTICS IO和SET STATISTICS TIME 【原】winform定制datagrid模板 【原】winform高效导出Excel带格式设置 【原】让3层下的objectDatasource,支持griedview不写代码具备编辑功能 推荐一个可以下.net电子书的论坛
JavaScript正则表达式exec和test方法实例! - 溶入海洋中的雨滴 - 博客园
溶入海洋中的雨滴 · 2009-04-17 · via 博客园 - 溶入海洋中的雨滴

<script LANGUAGE="javascript">
var u="http://msdn.microsoft.com:80/scripting/default.htm";
var s=/(\w+):\/\/([^/:]+)(:\d*)?([^# ]*)/;
var a=s.exec(u);
for(i=1;i<a.length;i++){
alert(a[i]);
}
</script>

将该正则表达式应用于上面所示的URL后,子匹配包含下述内容:
a[1] 包含 "http"
a[2] 包含 "msdn.microsoft.com"
a[3] 包含 ":80"
a[4] 包含 "/scripting/default.htm"
(也可以用RegExp.$1、RegExp.$2、RegExp.$3、RegExp.$4取值)

<script LANGUAGE="javascript">
function checkMobile( s )...{
var regu =/^[1][3][0-9]...{9}$/;
var re = new RegExp(regu);
return re.test(s);
}
checkMobile('13909910000');
</script>

用途:检查输入手机号码是否正确,如果通过验证返回true,否则返回false

正则表达式的创建,有2种办法:
var my_regex=/[a-z]+/g;
var my_regex=new (”[a-z]+”,"g”);

方法
exec(string): 对string进行正则处理,并返回匹配结果.
exec方法返回的数组有3个属性,分别是input、index和lastIndex 。
1 input 属性是整个被搜索的字符串。
2 index属性是指匹配在整个被搜索字符串中的位置。
3 lastIndex 属性是指匹配的子字符串的最后一个字符的下一个字符位置。

test(string): 测试string是否含有匹配结果

字符串对象中的正则
方法
match(pattern) :根据pattern进行正则匹配,如果匹配到,返回匹配结果,如匹配不到返回null
search(pattern) :根据pattern进行正则匹配,如果匹配到一个结果,则返回它的索引数;否则返回-1
replace(pattern,replacement) :根据pattern进行正则匹配,把匹配结果替换为replacement
split(pattern) :根据pattern进行正则分割,返回一个分割的数组