Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save Nebyu/7b4b45c831f50e74a1437dea77256cc3 to your computer and use it in GitHub Desktop.

Select an option

Save Nebyu/7b4b45c831f50e74a1437dea77256cc3 to your computer and use it in GitHub Desktop.

Revisions

  1. @LeCoupa LeCoupa revised this gist Nov 10, 2017. No changes.
  2. Julien Le Coupanec revised this gist Oct 24, 2014. 1 changed file with 9 additions and 10 deletions.
    19 changes: 9 additions & 10 deletions regular-expressions.cheatsheet.coffee
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,10 @@
    ## SYNTAX:
    # SYNTAX:

    var pattern = new RegExp(pattern, attributes); # attributes: g (global); i (case-sensitive); m (multiline matches)
    var pattern = /pattern/attributes; # same as above


    ## BRACKETS:
    # 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:
    # 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:
    # LITERAL CHARACTERS:

    Alphanumeric: Itself.
    \0: The NUL character (\u0000).
    @@ -37,7 +37,7 @@ Alphanumeric: Itself.
    \r: Carriage return (\u000D).


    ## METACHARACTERS:
    # 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:
    # 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:
    # 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 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:
    # 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+\/>)$/

  3. Julien Le Coupanec revised this gist May 7, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion regular-expressions.cheatsheet.coffee
    Original 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 EXPRESSION YOU SHOULD KNOW:
    ## 8 REGULAR EXPRESSIONS YOU SHOULD KNOW:

    Matching a Username: /^[a-z0-9_-]{3,16}$/
    Matching a Password: /^[a-z0-9_-]{6,18}$/
  4. Julien Le Coupanec revised this gist May 7, 2014. 1 changed file with 9 additions and 9 deletions.
    18 changes: 9 additions & 9 deletions regular-expressions.cheatsheet.coffee
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,10 @@
    SYNTAX:
    ## SYNTAX:

    var pattern = new RegExp(pattern, attributes); # attributes: g (global); i (case-sensitive); m (multiline matches)
    var pattern = /pattern/attributes; # same as above


    BRACKETS:
    ## 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:
    ## 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:
    ## LITERAL CHARACTERS:

    Alphanumeric: Itself.
    \0: The NUL character (\u0000).
    @@ -37,7 +37,7 @@ Alphanumeric: Itself.
    \r: Carriage return (\u000D).


    METACHARACTERS:
    ## 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:
    ## 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:
    ## 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 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:
    ## 8 REGULAR EXPRESSION YOU SHOULD KNOW:

    Matching a Username: /^[a-z0-9_-]{3,16}$/
    Matching a Password: /^[a-z0-9_-]{6,18}$/
  5. Julien Le Coupanec revised this gist May 7, 2014. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion regular-expressions.cheatsheet.coffee
    Original 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)
  6. Julien Le Coupanec created this gist May 7, 2014.
    92 changes: 92 additions & 0 deletions regular-expressions.cheatsheet.coffee
    Original 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+\/>)$/