我需要能夠在PHP中提取以下內容,並且這讓我發瘋。PHP正則表達式的百分比或貨幣
就拿以下字符串:
$text = "Nalgene Narrow-Mouth Loop-Top 16-oz. Water Bottle for $4 + pickup and %40 off at REI";
,一方面,我需要能夠提取:
$4 as extracted currency
和
%40 as extracted percentage
並區分哪一個是貨幣,哪個是百分比。
爲了使它有點複雜,我也應該抓住它,如果貨幣would'be了:
$4.11 or $ 4.10 (not the spacing and the comma)
,或者如果百分比會一直:
% 40 (note the spacing)
我真的被卡住了,謝謝..
地球上數字之前寫的是百分號嗎? – Qtax
你是對的;)但它發生......雜亂的飼料。 –