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"