【发布时间】:2020-06-28 01:09:58
【问题描述】:
我试图在我的字符串中找到一个多行子字符串。
我的代码:
data = `if (res) {
new PNotify({
title: TAPi18n.__('success'),
text: TAPi18n.__('image_uploaded'),
type: 'info',
styling: 'bootstrap3'
});
}
if (err) {
return new PNotify({
title: TAPi18n.__('error'),
text: err,
type: 'error',
styling: 'bootstrap3'
});
}`;
/*not found...*/
match = `new PNotify({
title: TAPi18n.__('error'),
text: err,
type: 'error',
styling: 'bootstrap3'
})`;
console.log(data);
console.log(match);
console.log(data.indexOf(match));
那行console.log(data.indexOf(match)); 显示了-1。
我的代码有什么问题?如何进行多行搜索?
【问题讨论】:
-
match每行开头的空格数与data的匹配部分不同。 -
如果你想允许可变数量的空格,你需要使用正则表达式。
标签: javascript string find multiline