且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

RegEx-如何提取价格?

更新时间:2023-02-20 08:10:52

我不是regex专家,但是可以使用 RegExr .

I'm no regex-guru, but was able to whip up the following with RegExr.

/(\$[0-9]+(\.[0-9]{2})?)/

匹配$35.03$35.要接受$35,000.52之类的格式,您需要包含,

Matches $35.03 and $35. To accept formats like $35,000.52 you would need to include ,

/(\$[0-9,]+(\.[0-9]{2})?)/

这可能会有所改善,但是从我的初步测试来看,它工作得很好.

This could likely be improved upon, but from my preliminary tests, it works just fine.