I read the book or search the web,and the result is said that .\n
is usually equal to \s\S
or \d\D
or \w\W
, which means all character.But now I want to get the message from some string,I find that I can only use .\n
.What's wrong with my code?Why can't I use \s\S
expression?
String srcMsg="<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<root><resultCode>00000</resultCode><resultDesc><![CDATA[00000:<ResponseClass Name=\"Response\">\n <ResponseSubClass Name=\"attributesResponse\">\n <ITEM>0</ITEM>\n </ResponseSubClass>\n</ResponseClass>]]></resultDesc></root>";
//The right code
java.util.regex.Pattern pP0 = java.util.regex.Pattern.compile(".*<!\\[CDATA\\[00000:((.|\n)*)\\]\\]>.*");
//wrong code1
//java.util.regex.Pattern pP0 = java.util.regex.Pattern.compile(".*<!\\[CDATA\\[00000:(\\s|\\S)*\\]\\]>.*");
//wrong code2
//java.util.regex.Pattern pP0 = java.util.regex.Pattern.compile(".*<!\\[CDATA\\[00000:[\\w|\\W]*\\]\\]>.*");
java.util.regex.Matcher mP0= pP0.matcher(srcMsg);
if(mP0.find())
para=mP0.group(1);
int dsi3 = para.indexOf("<ITEM>") + "<ITEM>".length();
int dsi4 = para.indexOf("</ITEM>");
System.out.println(Integer.valueOf(para.substring(dsi3, dsi4)));