例子:
blah blah * Match this text Match this text
Match this text
Match this text
Match this text
*
more text more text
如何从星号内部使用换行符获取字符串?
您可以在此处使用否定匹配。注意到我逃脱了\
此示例的文字换行符。
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 "
See Working demo https://eval.in/82302
如果您不需要前导或尾随空格,可以使用以下命令使其成为非贪婪的。
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"
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)