javascript正则表达式替换多行字符串

时间:2016-05-18 09:34:25

标签: javascript regex

我在我的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}

任何想法为什么?

0 个答案:

没有答案