Skip to content

Latest commit

 

History

History
87 lines (49 loc) · 2.47 KB

Tips.Regex.md

File metadata and controls

87 lines (49 loc) · 2.47 KB

Regular Express (Regex) Resources

References

Basic Syntax Notes

  • | boolean condition (e.g. grey|gray)

  • Parentheses are used to define the scope and precedence of the operators (among other uses)

  • ? zero or one occurences of the preceding element

  • * zero or more occurences of the preceding element

  • + one or more occurences of the preceding element

  • * match any character

  • ^ Matches the starting positon within the string

  • . Matches any single character

  • [] Matches a single character that is contained within the brackets

    • [a-z] specified a range which matches any lowercase letter
    • [^abc] matches any character that is not "a", "b", or "c"
    • [^a-z] matches any character that is not a lowercase letter from "a" to "z"
  • () Defines a marked subexpression (also called a block or capturing group)

  • \n Matches what the nth marked subexpression matched

  • $ Matches the ending position of the string, or the position just before a string-ending newline

  • {n} preceding item is matched exactly n times

  • 
    
  • \ escape sequence

  • \w word

  • \d digit

  • \s whitespace

Tutorials

Interesting Regex Articles

Suggested Books

Tools

Exemplars

  • .at

    • Matches any three-character string ending with "at"
  • [hc]at

    • Matches "hat" and "cat"
  • [^b]at

    • Matches all strings matched by .at except "bat"
  • (?<=\.) {2,}(?=[A-Z])

    • At least two spaces are matched, but only if they occur directly after a period (.) and before an uppercase letter.