我怎樣才能從這個字串中取出中間的 2 個數字Price Our:
和下面的 數字|?
"Delivery: Price => 30.00 - 45.00 | Price Our: 1900.00 => 1800.00 | Delivery: Contact => 3 - 4 Days | "
我試過了,(Price Our:.*?(?=\|))但這就是我的正則運算式知識的極限
uj5u.com熱心網友回復:
您可以使用 2 個捕獲組:
\bPrice Our: (\d (?:\.\d )?) => (\d (?:\.\d )?) \|
模式匹配:
\bPrice Our:防止部分匹配的單詞邊界,然后匹配Price Our:(\d (?:\.\d )?)捕獲組 1,匹配一個帶有可選小數部分的數字=>字面匹配(\d (?:\.\d )?)捕獲組 2,匹配一個帶有可選小數部分的數字\|比賽|

const regex = /(\d*\.\d )/gm;
const str = "Delivery: Contact => 3 - 4 Days | Price Our: 1900.00 => 1800.00 | Delivery: Contact => 3 - 4 Days | ";
const res = str.match(regex)
console.log(res)
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/321133.html
標籤:javascript 正则表达式
