我在我的javascript中运行正则表达式替换,看起来像这样,
this.set('activity', activity.replace(/{(object)}(.*?){\/\1}/gi, '<a href="' + object_link + '" class="' + linkClass + '">$2</a>'));
this.set('activity', activity.replace(/{(object)}(.*?){\/\1}/gi, '<a href="' + object_link + '" class="' + linkClass + '">$2</a>'));
当字符串看起来像这样时,上面的效果很好,
{blockquote}{object}Joe Bloggs{/object} did something great!{/blockquote}
但是如果字符串是多行的,即
{blockquote}{object}Joe Bloggs{/object} did something great
and it broke on to two lines{/blockquote}
我以为我可以将多行检查添加到我的regExp中,就像这样,
this.set('activity', activity.replace(/{(object)}(.*?){\/\1}/gmi, '<a href="' + object_link + '" class="' + linkClass + '">$2</a>'));
this.set('activity', activity.replace(/{(object)}(.*?){\/\1}/gmi, '<a href="' + object_link + '" class="' + linkClass + '">$2</a>'));
但它没有像单行文本一样解析{object}和{blockquotes}
任何想法为什么?