且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

正则表达式将 BBCode 拆分为多个部分

更新时间:2022-11-12 09:36:34

irb(main):001:0> str = "some html code [img]......[/img] some html \
code [img]......[/img]"
"some html code [img]......[/img] some html code [img]......[/img]"
irb(main):002:0> str.scan(/\[img\].*?\[\/img\]/)
["[img]......[/img]", "[img]......[/img]"]

请记住,这是基于您的确切问题的非常具体的答案.更改 str,例如,在图像标记中添加图像标记,以及 所有的地狱都会崩溃.

Keep in mind that this is a very specific answer that is based on your exact question. Change str by, say, adding an image tag within an image tag, and all Hell will break loose.