请帮我拆分一个字符串以放入一个数组中。
细绳:
<p>TEXT1</p>
<p><img src="img1.jpg"></p>
<p>TEXT 2</p>
<p><img src="img2.jpg"></p>
<p>TEXT3</p>
我需要把它分开
<p><img src="*****"></p>
在结果数组中:
result[0]:
<p>TEXT1</p>
<p><img src="img1.jpg"></p>
result[1]
<p>TEXT 2</p>
<p><img src="img2.jpg"></p>
result[2]
<p>TEXT3</p>
升级版:
:001> str = '<p>TEXT 1</p><p><img src="/upload/posts/13/009781884.jpg"></p><p>TEXT 2</p><p><img src="/upload/posts/14/010098317.jpg"></p><p>TEXT3</p>'
:002> array = str.scan(/<p>[a-zA-Z 0-9<\/>]*<img src="[\/a-zA-Z0-9.]*"><\/p>|<p>[a-zA-Z 0-9\d\D]*<\/p>/)
=> ["<p>TEXT 1</p><p><img src=\"/upload/posts/13/009781884.jpg\"></p>", "<p>TEXT 2</p><p><img src=\"/upload/posts/14/010098317.jpg\"></p>", "<p>TEXT3</p>"]