example regex

Example 1: regex examples

\d         matches a single character that is a digit -> Try it!\w         matches a word character (alphanumeric character plus underscore) -> Try it!\s         matches a whitespace character (includes tabs and line breaks).          matches any character -> Try it!

Example 2: regex examples

\$\d       matches a string that has a $ before one digit -> Try it!

Example 3: regex examples

abc*        matches a string that has ab followed by zero or more c -> Try it!abc+        matches a string that has ab followed by one or more cabc?        matches a string that has ab followed by zero or one cabc{2}      matches a string that has ab followed by 2 cabc{2,}     matches a string that has ab followed by 2 or more cabc{2,5}    matches a string that has ab followed by 2 up to 5 ca(bc)*      matches a string that has a followed by zero or more copies of the sequence bca(bc){2,5}  matches a string that has a followed by 2 up to 5 copies of the sequence bc

Example 4: regex examples

^The        matches any string that starts with The -> Try it!end$        matches a string that ends with end^The end$   exact string match (starts and ends with The end)roar        matches any string that has the text roar in it

Example 5: regex examples

[abc]            matches a string that has either an a or a b or a c -> is the same as a|b|c -> Try it![a-c]            same as previous[a-fA-F0-9]      a string that represents a single hexadecimal digit, case insensitively -> Try it![0-9]%           a string that has a character from 0 to 9 before a % sign[^a-zA-Z]        a string that has not a letter from a to z or from A to Z. In this case the ^ is used as negation of the expression -> Try it!

Tags:

R Example