cheatsheet <- tibble::tribble(
~category, ~group, ~regexp, ~text,
"character classes", "regular", ".", "any character except newline",
"character classes", "regular", "\\w \\d \\s", "word, digit, whitespace",
"character classes", "regular", "\\W \\D \\S", "not word, digit, whitespace",
"character classes", "regular", "\\p{property name}", "matches character with unicode property, like \\p{Uppercase}, see unicode property list.",
"character classes", "regular", "[abc]", "any of a, b or c",
"character classes", "regular", "[^abc]", "not a, b, or c",
"character classes", "regular", "[a-g] [1-3]", "character between a & g or 1 & 3",
"character classes", "regular", "[\\^\\-]", "matches - or \\",
"character classes", "pre-built", "Used inside []", "Example [[:digit:]AX] matches all digits and A and X",
"character classes", "pre-built", "[:punct:]", "punctuation",
"character classes", "pre-built", "[:alpha:]", "letters",
"character classes", "pre-built", "[:lower:]", "lowercase letters",
"character classes", "pre-built", "[:upper:]", "uppercase letters",
"character classes", "pre-built", "[:digit:]", "digits",
"character classes", "pre-built", "[:xdigit:]", "hex digits",
"character classes", "pre-built", "[:alnum:]", "letters and numbers",
"character classes", "pre-built", "[:cntrl:]", "control characters",
"character classes", "pre-built", "[:graph:]", "letters, numbers, and punctuation",
"character classes", "pre-built", "[:print:]", "letters, numbers, punctuation, and whitespace",
"character classes", "pre-built", "[:space:]", "space characters (basically equivalent to \\s)",
"character classes", "pre-built", "[:blank:]", "space and tab",
"anchors", NA, "^", "start of string",
"anchors", NA, "$", "end of string",
"anchors", NA, "\\b", "word boundary",
"anchors", NA, "\\B", "not-word boundary",
"anchors", NA, "\\A", "stringr multiline: match start of the input",
"anchors", NA, "\\z", "stringr multiline: match end of the input",
"anchors", NA, "\\Z", "stringr multiline: match end of the input, but before final line terminator (if it exists)",
"escaped characters", "general", "\\.", "dot",
"escaped characters", "general", "\\*", "asterisk",
"escaped characters", "general", "\\\\", "backslash",
"escaped characters", "general", "\\t", "tab",
"escaped characters", "general", "\\n", "linefeed",
"escaped characters", "general", "\\r", "carriage return",
"escaped characters", "hex", "\\xhh", "2 hex digits",
"escaped characters", "hex", "\\x{hhhh}", "1-6 hex digits",
"escaped characters", "hex", "\\uhhhh", "4 hex digitis",
"escaped characters", "hex", "\\Uhhhhhhhh", "8 hex digits",
"escaped characters", "hex", "\\N{name}", "Name of unicode character, e.g. \\N{grinning face}",
"escaped characters", "control characters", "\\a", "bell",
"escaped characters", "control characters", "\\cX", "match a control-X character",
"escaped characters", "control characters", "\\e", "escape (\\u001B)",
"escaped characters", "control characters", "\\f", "form feed (\\u000C)",
"escaped characters", "control characters", "\\0ooo", "octal character where \"ooo\" is 1-3 octal digits",
"groups", NA, "(abc)", "capture group",
"groups", NA, "\\", "backreference to group #N, e.g. \\1",
"groups", NA, "(?:abc)", "non-capturing group, e.g. \"gr(?:e|a)y\")",
"groups", NA, "(?=abc)", "postive lookahead; matches are followed by abc (non-capturing)",
"groups", NA, "(?!abc)", "negative lookahead; matches are not followed by abc (non-capturing)",
"groups", NA, "(?<=abc)", "positive lookbehind; matches are preceeded by abc (non-capturing)",
"groups", NA, "(?", "negative lookbehind; matches are not preceeded by abc (non-capturing)",
"groups", NA, "(?>abc)", "atomic-match; no back-tracking if later matches fail",
"quantifiers", NA, "a*", "0 or more",
"quantifiers", NA, "a+", "1 or more",
"quantifiers", NA, "a?", "0 or 1",
"quantifiers", NA, "a{n}", "exactly n times",
"quantifiers", NA, "a{n,}", "n or more times",
"quantifiers", NA, "a{n,m}", "n-m times",
"quantifiers", NA, "add +", "makes match possessive",
"quantifiers", NA, "add ?", "makes match non-greedy",
"quantifiers", NA, "ab|cd", "match ab or cd",
"quantifiers", NA, "w(?:o|a)ke", "use non-capturing group for precedence"
)