Here is my code
这是我的代码
Pattern pbold = Pattern.compile(".*\\* *(.*?) *\\*.*");
Matcher mbold = pbold.matcher(s);
mbold.find();
3 个解决方案
#1
1
What you need is the metacharacter that matches whitespaces charaters: (?s)
This whitespace metacharacter matches:
你需要的是匹配空格字符的元字符:(?s)这个空格元字符匹配:
- A space character
- A tab character
- A carriage return character
- A new line character
- A vertical tab character
空间角色
标签字符
回车符
一个新的线条字符
垂直制表符
For more info about this special characters, please consult The Java Tutorials - Regular Expressions - Predefined Character Classes.
有关此特殊字符的更多信息,请参阅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
这里也有类似的问题:正则表达式与从Formatter对象获得的换行符不匹配
#2
0
Use flags igm like below:
使用标志igm如下:
Pattern pbold = Pattern.compile(".*\\* *(.*?) *\\*.*");
Matcher mbold = pbold.matcher(s, Pattern.MULTILINE|Pattern.CASE_INSENSITIVE|Pattern.DOTALL);
mbold.find();
#3
0
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.
如果这不能解决它...请详细说明您试图通过此表达式获得的内容。
#1
1
What you need is the metacharacter that matches whitespaces charaters: (?s)
This whitespace metacharacter matches:
你需要的是匹配空格字符的元字符:(?s)这个空格元字符匹配:
- A space character
- A tab character
- A carriage return character
- A new line character
- A vertical tab character
空间角色
标签字符
回车符
一个新的线条字符
垂直制表符
For more info about this special characters, please consult The Java Tutorials - Regular Expressions - Predefined Character Classes.
有关此特殊字符的更多信息,请参阅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
这里也有类似的问题:正则表达式与从Formatter对象获得的换行符不匹配
#2
0
Use flags igm like below:
使用标志igm如下:
Pattern pbold = Pattern.compile(".*\\* *(.*?) *\\*.*");
Matcher mbold = pbold.matcher(s, Pattern.MULTILINE|Pattern.CASE_INSENSITIVE|Pattern.DOTALL);
mbold.find();
#3
0
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.
如果这不能解决它...请详细说明您试图通过此表达式获得的内容。