使用正则表达式进行解析
我有一些文本,例如
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 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
然而,我不知道如何将文本包装在
中。我在 iPhone 上使用 RegexKitLite 完成所有操作
I have some text like
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
Which I need to transform into
<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>
To get the <img>
tags, I replaced \[(.*?)\]
with <img src="$1"/>
, resulting in
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
However, I have no idea how to wrap the text in a <div>
.
I'm doing everything on the iPhone with RegexKitLite
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最简单的方法如下:
\[(.*?)\]
替换为这确实有一个极端情况,结果以以下形式开始或结束
,但这可能并不重要。
如果是,则:
\](.*?)\[
替换为]$1
[
\[(.*?)\]
与Here's the simplest approach:
\[(.*?)\]
with</div><img src="$1"/><div>
<div>
</div>
That does have a corner case where the result starts or ends with
<div></div>
, but this probably doesn't matter.If it does, then:
\](.*?)\[
with]<div>$1</div>[
\[(.*?)\]
with<img src="$1"/>