Regex to split BBCode into pieces
问题 I have this: str = \"some html code [img]......[/img] some html code [img]......[/img]\" and I want to get this: [\"[img]......[/img]\",\"[img]......[/img]\"] 回答1: 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