Here is my code
Pattern pbold = Pattern.compile(".*\\* *(.*?) *\\*.*");
Matcher mbold = pbold.matcher(s);
mbold.find();
Here is my code
Pattern pbold = Pattern.compile(".*\\* *(.*?) *\\*.*");
Matcher mbold = pbold.matcher(s);
mbold.find();
What you need is the metacharacter that matches whitespaces charaters: (?s)
This whitespace metacharacter matches:
For more info about this special characters, please consult The Java Tutorials - Regular Expressions - Predefined Character Classes.
The code belows matches the case you need:
String s = "abc021\n" +
"34-+\n" +
"*\n" +
"a\n" +
"p\n" +
"p\n" +
"l\n" +
"e\n" +
"*\n" +
"fga32\n" +
"49";
Pattern pbold = Pattern.compile(".*\\* *((?s).*?) *\\*.*");
Matcher mbold = pbold.matcher(s);
mbold.find();
There is also a similar question here: Regular expression does not match newline obtained from Formatter object
Use flags igm like below:
Pattern pbold = Pattern.compile(".*\\* *(.*?) *\\*.*");
Matcher mbold = pbold.matcher(s, Pattern.MULTILINE|Pattern.CASE_INSENSITIVE|Pattern.DOTALL);
mbold.find();
This regular expression might solve your problem...
Pattern pbold = Pattern.compile(".*\\*[ \n]*(.*?)[ \n]*\\*.*");
Matcher mbold = pbold.matcher(s);
mbold.find();
If this doesn't solve it..please elaborate what you are trying to get through this expression.