Last active
February 8, 2016 21:39
-
-
Save Blumed/46c61d8b2421aa2cf759 to your computer and use it in GitHub Desktop.
Regex Svg Cleaning
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# In sublime text must turn on regex and case sensativity. | |
#Grabs all attributes that start with sketch until last second qoute. | |
\ssketch.[^"]*(["'])(?:(?=(\\?))\2.)*?\1 | |
#Grabs all attributes that start with font-weight until last second qoute. | |
\sfont-w.[^"]*(["'])(?:(?=(\\?))\2.)*?\1 | |
#Grabs def,desc,title,svg tags and comments | |
(?=(<def)|(<desc)|(<title)|(<\!)|(<svg)|(<\/svg)|(<\?)).+ | |
#These don't work for <path + id=".*" | |
id="[^"]*" | |
(^[<path])id+.[^"]*(["'])(?:(?=(\\?))\2.)*?\1 | |
[^(?=(g)|(text)(rect))]\ id+.[^"]*(["'])(?:(?=(\\?))\2.)*?\1 | |
#Process | |
#1. Remove unnedded html tags | |
(?=(<def)|(<desc)|(<title)|(<\!)|(<svg)|(<\/svg)|(<\?)).+ | |
#2. Remove empty lines | |
^\s*$ | |
or ^(\s*)[^<] this goes until the first < but won't include it | |
(?:(\<\/\g\>)).\s* this grabs everthing from the last <\g> and all white space after | |
#3. Remove first and last line // crappy sketch wrapper which is useless | |
#4. Remove sketch attributes | |
\ssketch.[^"]*(["'])(?:(?=(\\?))\2.)*?\1 | |
#5. Remove font-weight | |
\sfont-w.[^"]*(["'])(?:(?=(\\?))\2.)*?\1 | |
#6. Make all id text lowercase | |
#7. Make all id underscores into mdash's | |
#8. Remove xlink:href="<!--base64-->" all images will its own path | |
\sxlink.[^"]*(["'])(?:(?=(\\?))\2.)*?\1 | |
Look into this http://facelessuser.github.io/RegReplace/usage/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment