验证下面三种类型的链接
http://localhost:11594/A6P5/index.html
http://localhost:11594/P5/index.html
http://localhost:11594/index.html A[可以是A或T这二个字母]\d*
P[就只有一个字母]\d*
验证是{A6P5}还是{P5}类型的链接
并取得字母后面的数字
http://localhost:11594/A6P5/index.html
http://localhost:11594/P5/index.html
http://localhost:11594/index.html A[可以是A或T这二个字母]\d*
P[就只有一个字母]\d*
验证是{A6P5}还是{P5}类型的链接
并取得字母后面的数字
解决方案 »
- ie 中 input type="file" 如何点击输入框弹出文件选择对话框?
- 手机浏览器是否支持JS脚本,请大家指点一下???
- 一个页面所有DIV class=1的层隐藏
- 修改一个JS滚动的效果的修改
- 请教关于iframe.location=""的出错问题?谢谢
- webqq 的效果怎么实现的?
- 各位高手注意了!!!!日期急难问题!!!!
- 求一表达式去除特定内容.
- 请帮忙调试一段程序
- Jquery 监听div外的click事件
- |zyciis| 如何在Jquery Ajax中的ajaxStart取得当前Ajax提交的url 谢谢
- 用javscript实现帮助文档,带有模糊查询既是索引功能(共同研究)
验证 含有 A6P5 的连接 并取得数字 6和5
和
验证 含有 P5 的连接 并取得数字 5是这样吗?
s = "http://localhost:11594/A6P5/index.html"
s = "http://localhost:11594/P5/index.html"
//s = "http://localhost:11594/index.html"var re = new RegExp("\/[AT](\\d+)P(\\d+)\/","");
if(re.test(s)){
alert("类型1");
var a = s.match(re);
alert(a[1] + "," + a[2])
}
else{
var re = new RegExp("\/P(\\d+)\/","");
if(re.test(s)){
alert("类型2")
var a = s.match(re);
alert(a[1])
}
else alert("类型3")
}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
<script language="javascript" type="text/javascript">
function doCHK()
{
var url;
//url="http://localhost:11594/A6P5/index.html";
//url="http://localhost:11594/P5/index.html ";
//url="http://localhost:11594/index.html ";
//var url="http://localhost:11594/P5/a3/index.html ";
url=document.getElementById("content1").value;
var reg1=new RegExp("((http:\/\/localhost:11594\/)(A6P5)(\/index.html))","ig");
var reg2=new RegExp("((http:\/\/localhost:11594\/)(P5)(\/index.html))","ig");
if (reg1.test(url)||reg2.test(url))
{
reg1.exec(url);
reg2.exec(url);
if ((RegExp.$3).length<4)
alert(RegExp.$1+"\n\n第一个数字:"+(RegExp.$3).substring(1,2));
else
alert(RegExp.$1+"\n\n第一个数字:"+(RegExp.$3).substring(1,2)+"\n第二个数字:"+(RegExp.$3).substring(3,4))
}else{
alert("不匹配");
}
}
</script>
<body>
<p>
正则匹配问题<br>
<input name="content1" type="text" id="content1" value="http://localhost:11594/A6P5/index.html" size="60">
<input name="BTN01" value="Test" type="button" onClick="javascript:doCHK();">
</p>
</body>
</html>