我有一些像
这样的文字some text [http://abc.com/a.jpg] here will be long text
can be multiple line breaks again [http://a.com/a.jpg] here will be other text
blah blah
我需要转变为
<div>some text</div><img src="http://abc.com/a.jpg"/><div>here will be long text
can be multiple line breaks again</div><img src="http://a.com/a.jpg"/><div>here will be other text
blah blah</div>
要获取<img>
代码,我将\[(.*?)\]
替换为<img src="$1"/>
,结果为
some text<img src="http://abc.com/a.jpg"/>here will be long text
can be multiple enters again<img src="http://a.com/a.jpg"/>here will be other text
blah blah
但是,我不知道如何将文本包装在<div>
。
我正在使用RegexKitLite在iPhone上做所有事情
答案 0 :(得分:2)
这是最简单的方法:
\[(.*?)\]
替换为</div><img src="$1"/><div>
<div>
</div>
这确实有一个极端情况,结果以<div></div>
开头或结尾,但这可能无关紧要。
若是,那么:
\](.*?)\[
替换为]<div>$1</div>[
\[(.*?)\]
替换为<img src="$1"/>