使用正则表达式解析
问题描述:
我有一个像使用正则表达式解析
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>
。
我在iPhone上做的一切与RegexKitLite
答
这里是最简单的方法:
- 与
</div><img src="$1"/><div>
- 前置更换的
\[(.*?)\]
所有出现一个<div>
- 附加一个
</div>
确实有一个结果以<div></div>
开始或结束的情况,但这可能没有关系。
如果确实如此,那么:
- 替换的
\](.*?)\[
所有出现的]<div>$1</div>[
- 与
<img src="$1"/>
谢谢:)但是任何其他的想法将是很好的替换所有
\[(.*?)\]
出现。因为我已经在使用这个逻辑了。 – 2011-06-15 01:34:24