是否有可能grep
以某种方式从文件中列出所有价格并列出输出?价格以“$”开头,可能包含数字,“,”和“。”。
我尝试过来自this question的最佳解决方案,但它们会输出包含价格的所有文件或整个字符串。
我使用的模式很简单:\$
我想要访问的网页:http://www.ned.org/
页面来源示例:
<p><strong>Better Understanding Public Attitudes and Opinions</strong>
</p>
<p>Democratic Ideas and Values</p>
<p>$43,270</p>
<p>To monitor and better understand public views on key social, political, and economic developments. Citizens’ opinions will be tracked, documented, and studied ahead of and after the country’s September 2016 parliamentary elections. The results and accompanying analysis will be disseminated through print and electronic publications, a website, and independent media.</p>
<p><strong> </strong></p>
我想从这段html输出类似于43,470或者可能是43270.只是懒得写一个解析器:)
答案 0 :(得分:2)
这样的事情似乎对我的测试很好:
imageView?.image = UIImage(named: imageName+".jpg")
imageView?.frame.size = CGSize(width: w, height: h)
imageView?.layer.opacity = 0
imageView?.center = self.moveButtons[idx].center
self.view.addSubview(imageView!)
UIView.animate(withDuration: 1.5, animations: {
imageView?.frame.origin.x += (imageView?.frame.size.width)!/2
imageView?.layer.opacity=1
self.playerImages[self.currentPlayer].bringSubview(toFront: self.view)
})
使用您的网页进行真实测试:
$ echo "$prices"
tomato $30.10
potato $19.1
apples=$2,222.1
oranges:$1
peach="$22.1",discount 10%,final price=$20
$ egrep -o '\$[0-9]+([.,][0-9]+)*' <<<"$prices"
$30.10
$19.1
$2,222.1
$1
$22.1
$20