1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > java 正则匹配 sql星号 正则表达式匹配星号和换行符之间的字符串

java 正则匹配 sql星号 正则表达式匹配星号和换行符之间的字符串

时间:2019-07-02 15:45:35

相关推荐

java 正则匹配 sql星号 正则表达式匹配星号和换行符之间的字符串

Example:

blah blah * Match this text Match this text

Match this text

Match this text

Match this text

*

more text more text

How to get string from inside the asterisk with the line breaks?

解决方案

You can use a negated match here. Notice that I escaped \ the literal newline for this example.

var myString = "blah blah * Match this text Match this text\

Match this text\

Match this text\

Match this text\

*\

more text more text";

var result = myString.match(/\*([^*]*)\*/);

console.log(result[1]);

// => " Match this text Match this text Match this text Match this text Match this text "

If you don't want the leading or trailing whitespace, you can use the following to make it non greedy.

var result = myString.match(/\*\s*([^*]*?)\s*\*/);

console.log(result[1]);

// => "Match this text Match this text Match this text Match this text Match this text"

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。