Skip to content

Instantly share code, notes, and snippets.

@Zorgatone
Last active December 7, 2015 14:31
Show Gist options
  • Save Zorgatone/a77dd01b61e4030b6545 to your computer and use it in GitHub Desktop.
Save Zorgatone/a77dd01b61e4030b6545 to your computer and use it in GitHub Desktop.
My personal collection of useful Regular Expressions for programming
/* File: regexutils.js */
/* Language: JavaScript */
/* http://scriptular.com/ */
// Match a standard email
var email = /(?:[a-z0-9!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+\/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])/i
// Match an HTML comment
var htmlComment = /<!--((?:(?!-->).)*)-->/;
// Match the Host and page address from an URL
var urlAndHost = /^(https?):\/\/((?:[A-Z0-9]*\.?)*)((?:\/?[A-Z0-9])*)/i;
// Match the url of an HTML image from the source code
var matchImgUrl = /<img[^>]+src="([^"]+)"[^>]+\/?>/i;
// Find any character that is not ASCII
var nonASCII = /[^\x00-\x7F]/;
// Find any unwanted tabs inside a code line
var non_ident_tabs = /(\S)[^\t]{2,}/;
// Find trailing space and lines
var trailingSpace = /[^\S\n]*\n*[^\S\n]+$/;
// Find Pascal comments
var pascalComment = /{([^}]*)}/;
// Find CPP comments
var cppComment = /(^|[^\S\n]|;|{\[\()\/\/(.*)/;
// Find ANSI C comments
var ansi_cComment = /(^|[^\S\n]|;|{\[\()\/\*(((\n|((?!\*\/).))*)*)\*\//;
// Compressing html with Google Html Compressor: command ->
// java -jar ./bin/HtmlCompressor.jar --compress-css --compress-js --js-compressor yui --remove-surrounding-spaces max ./nl.html > ./nl.min.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment