Skip to content

Instantly share code, notes, and snippets.

@charrismatic
Last active August 4, 2023 07:11
Show Gist options
  • Save charrismatic/ff74aca9ab14f8dfd377ec67411b8caf to your computer and use it in GitHub Desktop.
Save charrismatic/ff74aca9ab14f8dfd377ec67411b8caf to your computer and use it in GitHub Desktop.
Useful Regex String List
regexLib = {
multiLineCComments: a("/\\*.*?\\*/", "gs"),
singleLineCComments: /\/\/.*$/gm,
singleLinePerlComments: /#.*$/gm,
doubleQuotedString: /"([^\\"\n]|\\.)*"/g,
singleQuotedString: /'([^\\'\n]|\\.)*'/g,
multiLineDoubleQuotedString: a('"([^\\\\"]|\\\\.)*"', "gs"),
multiLineSingleQuotedString: a("'([^\\\\']|\\\\.)*'", "gs"),
xmlComments: a("(&lt;|<)!--f.*?--(&gt;|>)", "gs"),
url: /\w+:\/\/[\w-.\/?%&=:@;#]*/g,
phpScriptTags: {
left: /(&lt;|<)\?(?:=|php)?/g,
right: /\?(&gt;|>)/g,
eof: !0
},
aspScriptTags: {
left: /(&lt;|<)%=?/g,
right: /%(&gt;|>)/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: /(&lt;|<)\s*script.*?(&gt;|>)/gi,
right: /(&lt;|<)\/\s*script\s*(&gt;|>)/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("(&lt;|<)!--f.*?--(&gt;|>)", "gs"),
url: /\w+:\/\/[\w-.\/?%&=:@;#]*/g,
phpScriptTags: {
left: /(&lt;|<)\?(?:=|php)?/g,
right: /\?(&gt;|>)/g,
eof: !0
},
aspScriptTags: {
left: /(&lt;|<)%=?/g,
right: /%(&gt;|>)/g
},
scriptScriptTags: {
left: /(&lt;|<)\s*script.*?(&gt;|>)/gi,
right: /(&lt;|<)\/\s*script\s*(&gt;|>)/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