![](/img/trans.png)
[英]Ruby Which regular expression pattern to replace \n\n to \n string
[英]Regular expression to read n number of count
我有一個HTML文檔,其中有很多PO編號。
我正在嘗試找回。 我對正則表達式不好。 我可以通過位置找到第一個沒有。 但我需要所有這些。 怎么做。
我的HTML文件看起來像
<html>
<head></head>
<body>
<br>
Invoice Number : [12346456] PO Number : [6464645]
<hr>
Invoice Number : [90156460] PO Number : [6416462]
<hr>
Invoice Number : [90868741] PO Number : [1613464]
</body>
</html>
我的密碼
po_count = page.css('body').text.scan(/\d+/)[1].to_i
我在哪個位置獲得第一個PO Number 6464645
我需要所有PO號
po_count = page.css('body').text.scan(/\d+/)
將生成匹配項數組
po_count = ["12346456", "6464645", "90156460", "6416462", "90868741", "1613464"]
po_count = po_count.map{|e| e.to_i}
將使
po_count = [12346456, 6464645, 90156460, 6416462, 90868741, 1613464]
不太瘦但是應該可以工作:
po_numbers = []
page.css('body').text.scan(/Invoice Number : \[\d+\] PO Number : \[(\d+)\]/) do
po_numbers << $1.to_i
end
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.