【发布时间】:2016-01-22 06:48:14
【问题描述】:
我有一个这样的字符串:
var str = " this is a [link][1]
[1]: http://example.com
and this is a [good website][2] in my opinion
[2]: http://goodwebsite.com
[3]: http://example.com/fsadf.jpg
[![this is a photo][3]][3]
and there is some text hare ..! ";
现在我想要这个:
var newstr = "this is a [link][1]
and this is a [good website][2] in my opinion
[![this is a photo][3]][3]
and there is some text hare ..!
[1]: http://example.com
[2]: http://goodwebsite.com
[3]: http://example.com/fsadf.jpg"
我该怎么做?
实际上,那个变量str 是一个textarea 的值......我正在尝试创建一个markdown 编辑器......所以我想要的与SO 的textarea 所做的完全一样。
这是我的尝试:
/^(\[[0-9]*]:.*$)/g 在第一行选择[any digit]:
我认为我应该使用() 为它创建一个组,然后用\n\n $1 替换它
【问题讨论】:
-
and there is some text hare ..!去哪儿了? -
@WiktorStribiżew 谢谢,我编辑了它
标签: javascript regex