I have svg
file which is stored in string format in javascript. I want to extract all the colors mentioned in file and stored it in array.
color information would be denoted as fill:#010101;
in file. I want to
- search
:#
characted in file - Extract assosoate hex color
- Store it in array
- Again search for next color
SVG File could vary from size 1kb
to 450Kb
. I can use .indexOf
to find first occurence of :#
but i am stuck in which method to use to get all colors in efficient way.
Here is a fiddle of what i have done : http://jsfiddle.net/mumg81qq/1/ even fiddle gets hanged due to my svg string :(
Edit : How to modify Javascript regex. Need to extract value from a SVG string this answer to get hex/rgb colors from svg string ?