Skip to content

Commit b3d344d

Browse files
separate selector regex from query regex
1 parent 279fc9f commit b3d344d

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

src/ElementQueries.js

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -179,19 +179,30 @@
179179
}
180180
}
181181

182-
var regex = /,?([^,\n]+?)\[[\s\t]*?(min|max)-(width|height)[\s\t]*?[~$\^]?=[\s\t]*?"([^"]*?)"[\s\t]*?]([^\n\s\{]*?)/mgi;
182+
var queryRegex = /\[(min|max)\-(width|height)[\b\~\|\^\$\*]=\"(\w*)\"/mgi;
183+
/**
184+
* @param {String} css
185+
*/
186+
function extractQuery(selector, css) {
187+
var match;
188+
while (null !== (match = queryRegex.exec(css))) {
189+
if (3 < match.length) {
190+
queueQuery(selector, match[1], match[2], match[3]);
191+
}
192+
}
193+
}
194+
195+
var selectorRegex = /(?:^|)([\.\#\[\]\-\w]*)\[(?:min|max)\-(?:width|height)[\~\|\^\$\*]?=\"\w*\"\](?:[\s,]|[^\]]+\]?([\.\#\-\w\~\|\^\$\*\=\"]+))/mgi;
183196

184197
/**
185198
* @param {String} css
186199
*/
187-
function extractQuery(css) {
200+
function extractSelector(css) {
188201
var match;
189-
var smatch;
190202
css = css.replace(/'/g, '"');
191-
while (null !== (match = regex.exec(css))) {
192-
if (5 < match.length) {
193-
smatch = match[1] || match[5] || smatch;
194-
queueQuery(smatch, match[2], match[3], match[4]);
203+
while (null !== (match = selectorRegex.exec(css))) {
204+
if (1 < match.length) {
205+
extractQuery(match[1] || match[2], match[0]);
195206
}
196207
}
197208
}

0 commit comments

Comments
 (0)