Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个简单的例子:
data = data.replace(/\/\*(.*?)\*\//g,"")
如何忽略此正则表达式中的换行符?
将m(多行)添加到您的正则表达式选项
m
data = data.replace(/\/\*(.*?)\*\//gm,"")
'。' 不匹配换行符。为了匹配换行符,您需要有字符集 [\s\S],换句话说,您将有:
data = data.replace(/\/\*([\s\S]*?)\*\//g,"")
请参阅此处进行快速演示。