Forked from LeCoupa/regular-expressions.cheatsheet.coffee
Created
March 15, 2018 22:41
-
-
Save Nebyu/7b4b45c831f50e74a1437dea77256cc3 to your computer and use it in GitHub Desktop.
Revisions
-
LeCoupa revised this gist
Nov 10, 2017 . No changes.There are no files selected for viewing
-
Julien Le Coupanec revised this gist
Oct 24, 2014 . 1 changed file with 9 additions and 10 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,10 +1,10 @@ # SYNTAX: var pattern = new RegExp(pattern, attributes); # attributes: g (global); i (case-sensitive); m (multiline matches) var pattern = /pattern/attributes; # same as above # BRACKETS: [...]: Any one character between the brackets. [^...]: Any one character not between the brackets. @@ -14,7 +14,7 @@ var pattern = /pattern/attributes; # same as above [a-Z]: It matches any character from lowercase a through uppercase Z. # QUANTIFIERS: p+: It matches any string containing at least one p. p*: It matches any string containing zero or more ps. @@ -26,7 +26,7 @@ p$: It matches any string with p at the end of it. ^p: It matches any string with p at the beginning of it. # LITERAL CHARACTERS: Alphanumeric: Itself. \0: The NUL character (\u0000). @@ -37,7 +37,7 @@ Alphanumeric: Itself. \r: Carriage return (\u000D). # METACHARACTERS: .: a single character. \s: a whitespace character (space, tab, newline). @@ -52,7 +52,7 @@ Alphanumeric: Itself. (foo|bar|baz): matches any of the alternatives specified. # REGULAR EXPRESSIONS PROPERTIES: constructor: Specifies the function that creates an object prototype. global: Specifies if the "g" modifier is set. @@ -62,23 +62,23 @@ multiline: Specifies if the "m" modifier is set. source: The text of the pattern. # REGULAR EXPRESSIONS METHODS: exec(): Executes a search for a match in its string parameter. test(): Tests for a match in its string parameter. toSource(): Returns an object literal representing the specified object; you can use this value to create a new object. toString(): Returns a string representing the specified object. # STRING METHODS: String.match(pattern): Matches given string with the RegExp. Returns an array containing the matches, a string or null. String.search(pattern): Matches RegExp with string and returns the index of the beginning of the match if found, -1 if not. String.replace(pattern,string): Replaces matches with the given string, and returns the edited string. String.split(pattern): Cuts a string into an array, making cuts at matches. # 8 REGULAR EXPRESSIONS YOU SHOULD KNOW: Matching a Username: /^[a-z0-9_-]{3,16}$/ Matching a Password: /^[a-z0-9_-]{6,18}$/ @@ -88,4 +88,3 @@ Matching an Email: /^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/ Matching a URL: /^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/ Matching an IP Address: /^(?:(?: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]?)$/ Matching an HTML Tag: /^<([a-z]+)([^<]+)*(?:>(.*)<\/\1>|\s+\/>)$/ -
Julien Le Coupanec revised this gist
May 7, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -78,7 +78,7 @@ String.replace(pattern,string): Replaces matches with the given string, and retu String.split(pattern): Cuts a string into an array, making cuts at matches. ## 8 REGULAR EXPRESSIONS YOU SHOULD KNOW: Matching a Username: /^[a-z0-9_-]{3,16}$/ Matching a Password: /^[a-z0-9_-]{6,18}$/ -
Julien Le Coupanec revised this gist
May 7, 2014 . 1 changed file with 9 additions and 9 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,10 +1,10 @@ ## SYNTAX: var pattern = new RegExp(pattern, attributes); # attributes: g (global); i (case-sensitive); m (multiline matches) var pattern = /pattern/attributes; # same as above ## BRACKETS: [...]: Any one character between the brackets. [^...]: Any one character not between the brackets. @@ -14,7 +14,7 @@ BRACKETS: [a-Z]: It matches any character from lowercase a through uppercase Z. ## QUANTIFIERS: p+: It matches any string containing at least one p. p*: It matches any string containing zero or more ps. @@ -26,7 +26,7 @@ p$: It matches any string with p at the end of it. ^p: It matches any string with p at the beginning of it. ## LITERAL CHARACTERS: Alphanumeric: Itself. \0: The NUL character (\u0000). @@ -37,7 +37,7 @@ Alphanumeric: Itself. \r: Carriage return (\u000D). ## METACHARACTERS: .: a single character. \s: a whitespace character (space, tab, newline). @@ -52,7 +52,7 @@ METACHARACTERS: (foo|bar|baz): matches any of the alternatives specified. ## REGULAR EXPRESSIONS PROPERTIES: constructor: Specifies the function that creates an object prototype. global: Specifies if the "g" modifier is set. @@ -62,23 +62,23 @@ multiline: Specifies if the "m" modifier is set. source: The text of the pattern. ## REGULAR EXPRESSIONS METHODS: exec(): Executes a search for a match in its string parameter. test(): Tests for a match in its string parameter. toSource(): Returns an object literal representing the specified object; you can use this value to create a new object. toString(): Returns a string representing the specified object. ## STRING METHODS: String.match(pattern): Matches given string with the RegExp. Returns an array containing the matches, a string or null. String.search(pattern): Matches RegExp with string and returns the index of the beginning of the match if found, -1 if not. String.replace(pattern,string): Replaces matches with the given string, and returns the edited string. String.split(pattern): Cuts a string into an array, making cuts at matches. ## 8 REGULAR EXPRESSION YOU SHOULD KNOW: Matching a Username: /^[a-z0-9_-]{3,16}$/ Matching a Password: /^[a-z0-9_-]{6,18}$/ -
Julien Le Coupanec revised this gist
May 7, 2014 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,3 @@ SYNTAX: var pattern = new RegExp(pattern, attributes); # attributes: g (global); i (case-sensitive); m (multiline matches) -
Julien Le Coupanec created this gist
May 7, 2014 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,92 @@ SYNTAX: var pattern = new RegExp(pattern, attributes); # attributes: g (global); i (case-sensitive); m (multiline matches) var pattern = /pattern/attributes; # same as above BRACKETS: [...]: Any one character between the brackets. [^...]: Any one character not between the brackets. [0-9]: It matches any decimal digit from 0 through 9. [a-z]: It matches any character from lowercase a through lowercase z. [A-Z]: It matches any character from uppercase A through uppercase Z. [a-Z]: It matches any character from lowercase a through uppercase Z. QUANTIFIERS: p+: It matches any string containing at least one p. p*: It matches any string containing zero or more ps. p?: It matches any string containing one or more ps. p{N}: It matches any string containing a sequence of N ps. p{2,3}: It matches any string containing a sequence of two or three ps. p{2, }: It matches any string containing a sequence of at least two ps. p$: It matches any string with p at the end of it. ^p: It matches any string with p at the beginning of it. LITERAL CHARACTERS: Alphanumeric: Itself. \0: The NUL character (\u0000). \t: Tab (\u0009). \n: Newline (\u000A). \v: Vertical tab (\u000B). \f: Form feed (\u000C). \r: Carriage return (\u000D). METACHARACTERS: .: a single character. \s: a whitespace character (space, tab, newline). \S: non-whitespace character. \d: a digit (0-9). \D: a non-digit. \w: a word character (a-z, A-Z, 0-9, _). \W: a non-word character. [\b]: a literal backspace (special case). [aeiou]: matches a single character in the given set. [^aeiou]: matches a single character outside the given set. (foo|bar|baz): matches any of the alternatives specified. REGULAR EXPRESSIONS PROPERTIES: constructor: Specifies the function that creates an object prototype. global: Specifies if the "g" modifier is set. ignoreCase: Specifies if the "i" modifier is set. lastIndex: The index at which to start the next match. multiline: Specifies if the "m" modifier is set. source: The text of the pattern. REGULAR EXPRESSIONS METHODS: exec(): Executes a search for a match in its string parameter. test(): Tests for a match in its string parameter. toSource(): Returns an object literal representing the specified object; you can use this value to create a new object. toString(): Returns a string representing the specified object. STRING METHODS: String.match(pattern): Matches given string with the RegExp. Returns an array containing the matches, a string or null. String.search(pattern): Matches RegExp with string and returns the index of the beginning of the match if found, -1 if not. String.replace(pattern,string): Replaces matches with the given string, and returns the edited string. String.split(pattern): Cuts a string into an array, making cuts at matches. 8 REGULAR EXPRESSION YOU SHOULD KNOW: Matching a Username: /^[a-z0-9_-]{3,16}$/ Matching a Password: /^[a-z0-9_-]{6,18}$/ Matching a Hex Value: /^#?([a-f0-9]{6}|[a-f0-9]{3})$/ Matching a Slug: /^[a-z0-9-]+$/ Matching an Email: /^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/ Matching a URL: /^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/ Matching an IP Address: /^(?:(?: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]?)$/ Matching an HTML Tag: /^<([a-z]+)([^<]+)*(?:>(.*)<\/\1>|\s+\/>)$/