[英]Regex to match the data between the double quotes
I have below strings我有以下字符串
1. "Settings Icon": "xxhdjxxx7wn"
2. "Settings Icon": "afewfwl"
3. "Settings Icon": "fdj ssde"
I want the regex to match all these strings by ignoring the content in right side of colon我希望正则表达式通过忽略冒号右侧的内容来匹配所有这些字符串
I have (['"])(?:(?.\1|\\).|\\.)*\1
which matches with content inside double quote. But couldn't solve above case.. Please help我有(['"])(?:(?.\1|\\).|\\.)*\1
与双引号内的内容匹配。但无法解决上述情况。请帮忙
If I understand you're question correctly, you only want the string within the quotes, from the left side of the colon.如果我理解你的问题是正确的,你只需要引号内的字符串,从冒号的左侧开始。 Is that correct?那是对的吗? If so, this might work for you:如果是这样,这可能对您有用:
(['"])([^\1]*?)\1:.*$
For this expression, capture group 2 will give you what you want.对于这个表达式,捕获组 2 会给你你想要的。
Use利用
const string = `1. "Settings Icon": "xxhdjxxx7wn" 2. "Settings Icon": "afewfwl" 3. "Settings Icon": "fdj ssde"` console.log( string.match(/(?<=")[^"]+(?=":)/g) )
DEMO演示
EXPLANATION解释
--------------------------------------------------------------------------------
(?<= 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
See regex proof .请参阅正则表达式证明。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.