[英]Regex to match basic media query
I am struggling to get my regular expression to match the following string: 我正在努力获取正则表达式以匹配以下字符串:
(max-width: 320px) 280px
I would like my regex to split the string into two parts like so: 我希望我的正则表达式将字符串分成两部分,如下所示:
console.log(parts[0]) // (max-width: 320px)
console.log(parts[1]) // 280px
This is what I currently have: 这是我目前拥有的:
(\(.+\))\s?(0-9a-z)+
I haven't written a regular expression in a while so I am a little rusty but for some reason, I cannot get it to match the final part ie 280px
. 我有一段时间没有写正则表达式了,所以有点生疏了,但是由于某种原因,我无法使其与最终部分(即
280px
匹配。
Can anyone advise what I am doing wrong? 谁能告诉我我在做什么错?
I do not need anything complex, the purpose of this regex is to match media queries used in the sizes
attribute of the an img
element. 我不需要任何复杂的东西,此正则表达式的目的是匹配
img
元素的sizes
属性中使用的媒体查询。
As far as I can see, it simply needs to do the following: 据我所知,它只需要执行以下操作:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.