我希望有一个模式匹配,在它(字母,数字,特殊charactres)拥有一切字符串Rexexp以匹配字符串
公共静态无效的主要(字符串[所有的数字,字母,特殊字符]参数){
String retVal=null;
try
{
String s1 = "[0-9a-zA-Z].*:[0-9a-zA-Z].*:(.*):[0-9a-zA-Z].*";
String s2 = "BNTPSDAE31G:BNTPSDAE:Healthcheck:Major";
Pattern pattern = null;
//if (! StringUtils.isEmpty(s1))
if ((s1 != null) && (! s1.matches("\\s*")))
{
pattern = Pattern.compile(s1);
}
//if (! StringUtils.isEmpty(s2))
if (s2 != null)
{
Matcher matcher = pattern.matcher(s2);
if (matcher.matches())
{
retVal = matcher.group(1);
// A special case/kludge for Asentria. Temp alarms contain "Normal/High" etc.
// Switch Normal to return CLEAR. The default for this usage will be RAISE.
// Need to handle switches in XML. This won't work if anyone puts "normal" in their event alias.
if ("Restore".equalsIgnoreCase (retVal))
{
}
}
}
}
catch(Exception e)
{
System.out.println("Error evaluating args : ");
}
System.out.println("retVal------"+retVal);
}
和输出是: 健康检查 荷拉使用该[0-9A-ZA-Z] *我匹配仅alpahbets和数字,但我想匹配。字符串如果有特殊字符,也
任何帮助,高度赞赏
什么是不允许的?我对这个问题有点困惑。你能帮我理解一下吗? – 2014-10-30 03:12:08