str = "some html code [img]......[/img] some html code [img]......[/img]"
I want use regex get the array:
["[img]......[/img]","[img]......[/img]"]
Any ideas anyone?
str = "some html code [img]......[/img] some html code [img]......[/img]"
I want use regex get the array:
["[img]......[/img]","[img]......[/img]"]
Any ideas anyone?
There is a ruby BBCODE parser at Google Code: http://code.google.com/p/ruby-bbcode/
Don't use regex for this.
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]"]
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.
Please don't use BBCode. It's evil.
BBCode came to life when developers were too lazy to parse HTML correctly and decided to invent their own markup language. As with all products of laziness, the result is completely inconsistent, unstandardized, and widely adopted.
Try to use a user-friendlier markup language, like Markdown (what StackOverflow uses) or Textile.
Both of them have parsers for Ruby: