I have written a (javascript) regex to match stylesheets in a page (css stylesheets between <style> tags to be more precise)
This code will populate an array with index 1: the complete first match, and 2: the first group of the first match:
While this code will populate an array with all matches (complete):
Now I want an array containing the first group for all matches (or maybe a multidimensional array containing both the complete match and the first group for all matches).
How can I achieve this?
Is the only possible way to do an additional regular expression on every element of the array?
This is the code for a firefox extension so it doesn't have to be cross-browser compatible.
Thanks,
Frederik Vanderstraeten
This code will populate an array with index 1: the complete first match, and 2: the first group of the first match:
| Code: |
| var stylesheets = asourceCode.match(/< *style *(?:type=['"]?text\/css['"]?)? *>[\r\n ]*(?:<!?--)?([^]+?)(?:(?:\/\/)?-->)?[\r\n ]*< *\/ *style *>/i); |
While this code will populate an array with all matches (complete):
| Code: |
| var stylesheets = asourceCode.match(/< *style *(?:type=['"]?text\/css['"]?)? *>[\r\n ]*(?:<!?--)?([^]+?)(?:(?:\/\/)?-->)?[\r\n ]*< *\/ *style *>/gi); |
Now I want an array containing the first group for all matches (or maybe a multidimensional array containing both the complete match and the first group for all matches).
How can I achieve this?
Is the only possible way to do an additional regular expression on every element of the array?
This is the code for a firefox extension so it doesn't have to be cross-browser compatible.
Thanks,
Frederik Vanderstraeten
