Please consider the following text :
String tempStr =
"$#<div style=\"text-align:left;\">$#Order-CAS No#$</div>$#abc#$";
Pattern p = Pattern.compile("(?<=\\$#)(\\w*)(?=#\\$)");
Matcher m = p.matcher(tempStr);
List<String> tokens = new ArrayList<String>();
while (m.find()) {
System.out.println("Found a " + m.group() + ".");
but it give me just abc..i want answer as Order-CASNo and abc.
The expression
\\w*does not match the hyphen or space. Try[\\w\\s-]*instead.Read more about character classes here: