Last active
August 4, 2023 07:11
-
-
Save charrismatic/ff74aca9ab14f8dfd377ec67411b8caf to your computer and use it in GitHub Desktop.
Useful Regex String List
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
regexLib = { | |
multiLineCComments: a("/\\*.*?\\*/", "gs"), | |
singleLineCComments: /\/\/.*$/gm, | |
singleLinePerlComments: /#.*$/gm, | |
doubleQuotedString: /"([^\\"\n]|\\.)*"/g, | |
singleQuotedString: /'([^\\'\n]|\\.)*'/g, | |
multiLineDoubleQuotedString: a('"([^\\\\"]|\\\\.)*"', "gs"), | |
multiLineSingleQuotedString: a("'([^\\\\']|\\\\.)*'", "gs"), | |
xmlComments: a("(<|<)!--f.*?--(>|>)", "gs"), | |
url: /\w+:\/\/[\w-.\/?%&=:@;#]*/g, | |
phpScriptTags: { | |
left: /(<|<)\?(?:=|php)?/g, | |
right: /\?(>|>)/g, | |
eof: !0 | |
}, | |
aspScriptTags: { | |
left: /(<|<)%=?/g, | |
right: /%(>|>)/g | |
}, | |
noSpaceBeforeBraces: /([\S]{1})\{/g | |
//MATCH SCRIPT SOURCE SRTRINGS | |
'scripts' : /src\=\"\..+functions.js\"/ | |
//MATCH SCRIPT HREF SRTRINGS | |
'hrefs' : href\=\"\..+\.css" , href\=\"[^"]* | |
// MATCH TEXT BETWEEN TAGS | |
'plaintext' : \>.+\< | |
// CONVERT IDS HTML TO CSS | |
'id-2-selector' : id\=\"([^"]*)\", #$1 | |
// RECURSIVE EXTRACT CLASSES (work in progress) | |
'class-2-selector' : \[([a-zA-Z1-9-_]+)[ ]\[ , .$1 | |
//\[(\S+)[ ]?[\]]? | |
// ALL CLOSING TAGS TO BRACES | |
\<\/.*\>, } | |
// CLOSING BRACES TO NEWLINE | |
(^\s+\S+)\}, $1\n\t} | |
// EXTRACT EVERYTHING TO JSON (BECAREFUL, TWO ADJACENT TAGS WILL GET MERGED) | |
\<(.*)\> , $1{ | |
scriptScriptTags: { | |
left: /(<|<)\s*script.*?(>|>)/gi, | |
right: /(<|<)\/\s*script\s*(>|>)/gi | |
} | |
} | |
// REGEXlint | |
// http://davidvgalbraith.com/how-i-fixed-atom/ | |
// function decreaseNextIndentRegex | |
// -- ^\s*[^\s()}]+(?<m>[^()]*\((?:\g<m>|[^()]*)\)[^()]*)*[^()]*\)[,]?$ | |
// SPACES AT START OF STRING -- ^\s* | |
// REMOVE EXTRA SPACES AFTER END OF WORDS | |
// -- \b[\s]{2,} -- [\w][\s]{2,}|[\s]{2,}[\w]| | |
// buffer.replace "^[^\r\n\d\S][\s]*", '' | |
// buffer.replace /^\n*\s*/, '\n' | |
// buffer.replace /\t/g, '\s\s' | |
// buffer.replace "/^.\s*", ''src\=\"\..+functions.js\" | |
// buffer.replace /\s\s/g, '\s' | |
// buffer.replace /\n\n/g, '\n' | |
// buffer.replace(/\t/g, '\s\s') | |
// buffer.replace /\r\n\r\n/g, '\r\n' | |
// buffer.replace(/^\n+/g, '\n') | |
// buffer.replace(/[\r\n]{3,}/g, '\n\n') | |
// whitespace.convert-all-tabs-to-spaces | |
// vv-- CAN'T PARSE / INSIDE | |
// /[\/]{1}[\*]{1,}[\n\r\s\*]{1,}[\*]?[^/]*[\n\r\s]{1,}[\*]{1,}[\/]{1} | |
// vv-- CAN'T PARSE MULTIPLE / / / (URL) | |
// /(\/[\*]{1,}[^\/]{1,})\/ *?([^\/]{0,}[\*]{1,}\/)/ | |
// /(\/[\*]{1,}[^\/]{1,})[\/]?([^\/]{0,}[\*]{1,}\/)/ | |
// /\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+/ | |
// /\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\/q | |
// \{([^\{\}]|[\s])+\} <--- EVERYTHING BETWEEN THE BRACES | |
// regexLib = { | |
multiLineCComments: a("/\\*.*?\\*/", "gs"), | |
singleLineCComments: /\/\/.*$/gm, | |
singleLinePerlComments: /#.*$/gm, | |
doubleQuotedString: /"([^\\"\n]|\\.)*"/g, | |
singleQuotedString: /'([^\\'\n]|\\.)*'/g, | |
multiLineDoubleQuotedString: a('"([^\\\\"]|\\\\.)*"', "gs"), | |
multiLineSingleQuotedString: a("'([^\\\\']|\\\\.)*'", "gs"), | |
xmlComments: a("(<|<)!--f.*?--(>|>)", "gs"), | |
url: /\w+:\/\/[\w-.\/?%&=:@;#]*/g, | |
phpScriptTags: { | |
left: /(<|<)\?(?:=|php)?/g, | |
right: /\?(>|>)/g, | |
eof: !0 | |
}, | |
aspScriptTags: { | |
left: /(<|<)%=?/g, | |
right: /%(>|>)/g | |
}, | |
scriptScriptTags: { | |
left: /(<|<)\s*script.*?(>|>)/gi, | |
right: /(<|<)\/\s*script\s*(>|>)/gi | |
} | |
} | |
// REGEXlint | |
// http://davidvgalbraith.com/how-i-fixed-atom/ | |
// function decreaseNextIndentRegex | |
// -- ^\s*[^\s()}]+(?<m>[^()]*\((?:\g<m>|[^()]*)\)[^()]*)*[^()]*\)[,]?$ | |
// SPACES AT START OF STRING -- ^\s* | |
// REMOVE EXTRA SPACES AFTER END OF WORDS | |
// -- \b[\s]{2,} -- [\w][\s]{2,}|[\s]{2,}[\w]| | |
// buffer.replace "^[^\r\n\d\S][\s]*", '' | |
// buffer.replace /^\n*\s*/, '\n' | |
// buffer.replace /\t/g, '\s\s' | |
// buffer.replace "/^.\s*", '' | |
// buffer.replace /\s\s/g, '\s' | |
// buffer.replace /\n\n/g, '\n' | |
// buffer.replace(/\t/g, '\s\s') | |
// buffer.replace /\r\n\r\n/g, '\r\n' | |
// buffer.replace(/^\n+/g, '\n') | |
// buffer.replace(/[\r\n]{3,}/g, '\n\n') | |
// whitespace.convert-all-tabs-to-spaces | |
// vv-- CAN'T PARSE / INSIDE | |
// /[\/]{1}[\*]{1,}[\n\r\s\*]{1,}[\*]?[^/]*[\n\r\s]{1,}[\*]{1,}[\/]{1} | |
// vv-- CAN'T PARSE MULTIPLE / / / (URL) | |
// /(\/[\*]{1,}[^\/]{1,})\/ *?([^\/]{0,}[\*]{1,}\/)/ | |
// /(\/[\*]{1,}[^\/]{1,})[\/]?([^\/]{0,}[\*]{1,}\/)/ | |
// /\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+/ | |
// /\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\/q | |
// \{([^\{\}]|[\s])+\} <--- EVERYTHING BETWEEN THE BRACES | |
// | |
space between - and / | |
.replace(/[\s]{1,}\-/g,"-") | |
.replace(/\-[\s]{1,}/g,"-") | |
.replace(/[\s]{1,}\-/g, -) | |
.replace(/\/(?![\s])/g, "/ ") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment