簡體   English   中英

正則表達式匹配雙引號之間的數據

[英]Regex to match the data between the double quotes

我有以下字符串

1. "Settings Icon": "xxhdjxxx7wn"
2. "Settings Icon": "afewfwl"
3. "Settings Icon": "fdj ssde"

我希望正則表達式通過忽略冒號右側的內容來匹配所有這些字符串

我有(['"])(?:(?.\1|\\).|\\.)*\1與雙引號內的內容匹配。但無法解決上述情況。請幫忙

如果我理解你的問題是正確的,你只需要引號內的字符串,從冒號的左側開始。 那是對的嗎? 如果是這樣,這可能對您有用:

(['"])([^\1]*?)\1:.*$

對於這個表達式,捕獲組 2 會給你你想要的。

利用

 const string = `1. "Settings Icon": "xxhdjxxx7wn" 2. "Settings Icon": "afewfwl" 3. "Settings Icon": "fdj ssde"` console.log( string.match(/(?<=")[^"]+(?=":)/g) )

演示

在此處輸入圖像描述

解釋

--------------------------------------------------------------------------------
  (?<=                     look behind to see if there is:
--------------------------------------------------------------------------------
    "                        '"'
--------------------------------------------------------------------------------
  )                        end of look-behind
--------------------------------------------------------------------------------
  [^"]+                    any character except: '"' (1 or more times
                           (matching the most amount possible))
--------------------------------------------------------------------------------
  (?=                      look ahead to see if there is:
--------------------------------------------------------------------------------
    ":                       '":'
--------------------------------------------------------------------------------
  )                        end of look-ahead

請參閱正則表達式證明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM