如何从字符串Ruby中提取单个段落

时间:2013-02-21 16:28:10

标签: ruby

在我的应用程序中,我试图从文章中提取第一段。我怎么能这样做?

2 个答案:

答案 0 :(得分:1)

可以通过以下方式完成:

test =  <<PARAGRAPH
I've actually been using the latest version of JAWS (the popular Windows screen reader software for blind people) recently, as part of my work on HTML5. From a usability point of view it is possibly the worst software I have ever used. I'm still horrified at how bad the accessibility situation is.

For example, JAWS will happily take the last sentence of a paragraph, and the first sentence of the next paragraph, and run them into each other as one sentence, if there's no full stop at the end of the first paragraph. If you really want to make your Web pages more readable to blind users, forget longdesc or even alt, or even markup of any kind, just make sure you're using full punctuation! And that's just one example.
'
PARAGRAPH

puts test[/(.*)/]   # This will print the first paragraph.

答案 1 :(得分:0)

一种方法:

>> str="<p>sadsda</p>"
=> "<p>sadsda</p>"
>> str.scan(/<p>(.*)<\/p>/)
=> [["sadsda"]]
>> str.scan(/<p>(.*)<\/p>/)[0]
=> ["sadsda"]