日期:2014-05-18  浏览次数:20722 次

求一个正则表达式.急.在线等.
如果有一个字符串,最大6位.可以输入1-6位.如果当前输入n位.那么n-1必须为字母或*号.如果不符合,则出错.

另外正则表达式如果匹配上的话,可以得到匹配的位置吗.

------解决方案--------------------
//上面写的有点问题,修正如下:
^[\\x00-\\xff]|[\\x00-\\xff]{0,4}[a-zA-Z*][\\x00-\\xff]$
------解决方案--------------------
String s = "abc*ea ";
Pattern p = Pattern.compile( "[a-zA-Z|\\*]{1,5}. ");
Matcher t = p.matcher(s);
if(!t.matches()){
while(t.find()){
System.out.println(t.group()+ ": "+t.start());//start就是不符合的位置
}
}else{
System.out.println(t.matches());
}
------解决方案--------------------
if(destination.value.length > 0){
var index=destination.value.search(re);
if ( index == -1) {
alert( "Destination character (i + 1) should be letter or asterix ");
destination.focus();
return false;
}
else{
alert( "position: "+index);
}

}