我希望有一個模式匹配,在它(字母,數字,特殊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