This document is written in Markdown, which is a small and simple formatted language, which can be rendered into a rich document. To view this document in a more readable way, open it on Github using your browser :)
Tokens | Description |
---|---|
[abc] |
Match a single character of a, b or c |
[^abc] |
Match a single character except a, b or c |
[a-z] |
Match a single character in the range of a to z |
[^a-z] |
Match a single character not in the range of a to z |
[a-zA-Z] |
Match a single character in the range of a to z or A to Z |
. |
Match any single character |
\s |
Match a single whitespace character |
\S |
Match a single non-whitespace character |
\d |
Match a single digit |
\D |
Match a single non-digit |
\w |
Match a single word character (similar to [a-zA-Z] but also includes underscore, umlauts etc.) |
\W |
Match a single non-word character |
\b |
Match a single word boundary |
\B |
Match a single non-word boundary |
\n |
Match a single newline |
\r |
Match a single carriage return (files originating from Windows terminate each line with \n\r , all other systems just \n ) |
\t |
Match a single tab character |
\p{P} or \p{Punct} |
Match a single punctuation character (in Python Regular Expressions) |
[[:punct:]] |
Match a single punctuation character (in egrep or grep -E Regular Expressions) |
Upsi|Lou |
Match either Upsi or Lou, note: prefer to use this with parenthesis |
(...) |
Capture any enclosed token(s), useful to reference back to the captured value or to group tokens with | (or) |
^(Upsi|Lou)$ |
Match either Upsi or Lou as the only word on a line (due to start and end tokens) |
^(auf|ab)\w+ |
Match a word starting with auf- or ab- |
(\w)\1 |
Match two consecutive word characters, \1 refers to the first group of parenthesis, \2 would refer to a second group |
\w? |
Match zero or one word character |
\w* |
Match zero or more word characters |
\w+ |
Match one or more word characters |
\w{3} |
Match exactly (any) three word characters |
\w{3,} |
Match three or more word characters |
\w{3,5} |
Match between three or five word characters |
^ |
Start of line or string |
$ |
End of line or string |
Write a regular expression to match the word "apple" in the given text.
Text: "I like apples and bananas."
Write a regular expression to match email addresses in the given text.
Text: "You can contact me at john.doe@example.com or jane_smith@email.co.uk."
Write a regular expression to match phone numbers in the format "(123) 456-7890" in the given text.
Text: "Please call (555) 123-4567 for more information."
Write a regular expression to match dates in the format "DD.DD.YYYY" in the given text.
Text: "The meeting is scheduled for 25.12.2023. Please confirm your attendance."
Write a regular expression to match URLs starting with "http://" or "https://" in the given text. URLs can include letters, numbers, hyphens, and periods.
Text: "Visit our website at http://www.example.com or https://blog.sample-site.net."
Write a regular expression to match hashtags (words starting with a #) in the given text. Text: "I love #programming and #coding challenges."
Write a regular expression to match any sequence of special characters in the given text. Text: "!!??%%%$$ This is a line with some special characters ##**@@".
Write a regular expression to match words containing hyphens in the given text.
Text: "The high-level programming language is user-friendly."
Write a regular expression to match words containing apostrophes (e.g., "can't" or "I'm") in the given text.
Text: "I can't believe I'm going to the party tonight."
Write a regular expression to match the words "cat" and "dog" in the given text.
Text: "My cat and dog are best friends."
Write a regular expression to match all alphabetic characters in the given text.
Text: "The quick brown fox jumps over the lazy dog."
Write a regular expression to match all digits in the given text.
Text: "12345 is a sequence of numbers."
Write a regular expression to match all alphanumeric characters in the given text.
Text: "A7B3x9zY2 is a mix of letters and numbers."
Write a regular expression to match all non-alphanumeric characters in the given text.
Text: "Special characters: !@#$%^&*()"
Write a regular expression to match all whitespace characters in the given text.
Text: "Tabs\tand spaces are whitespace characters."
Write a regular expression to match all word characters (letters, digits, and underscore) in the given text.
Text: "Regex_123 and Python3 are examples of word characters."
Write a regular expression to match all punctuation characters in the given text.
Text: "Punctuation marks: .,;?!-"
Write a regular expression to match all lowercase letters in the given text.
Text: "The quick brown fox."
Write a regular expression to match all uppercase letters in the given text.
Text: "The ABBR is an abbreviation."
Write a regular expression to match all alphabetic characters between 'm' and 'r' (inclusive) in the given text.
Text: "The summer vacation is marvelous!"
Write a regular expression to match lines that start with the word "Hello" in the given text.
Text:
Hello, how are you?
Hi there!
Hello, it's a beautiful day.
Write a regular expression to match lines that end with the word "goodbye" or "goodbye" with any punctuation in the given text.
Text:
Saying goodbye to friends is hard.
Goodbye, see you later!
Have a great day, not just a goodbye.
Saying goodbye
to your dog is very hard.
Write a regular expression to match lines that both start and end with the word "start" in the given text.
Text:
Start your engines and get ready to start!
The race is about to start.
The end is just as important as the start.
Write a regular expression to match lines that contain the exact word "apple" in the given text. "Apple" should not be part of another word.
Text:
I have an apple and a pineapple.
The apple is red.
He's very happy.
Write a regular expression to match empty lines (lines with no characters) in the given text.
Text:
This is a line with content.
Another empty line.
Write a regular expression to match lines that start with one or more digits in the given text.
Text:
123 Main Street
Avenue 456
No digits here.
42 is the answer.
Write a regular expression to match lines that end with one or more digits in the given text.
Text:
Apples 123
No numbers in this line.
99 bottles of beer on the wall 42
Write a regular expression to match lines that contain at least one uppercase letter in the given text.
Text:
hello world
No uppercase letters here.
This Line Has Uppercase Letters
Write a regular expression to match lines that contain the word "car" as a whole word in the given text.
Text:
Cars are cool.
My car is fast.
Carpet is soft.
I'm going to the car shop.
Write a regular expression to match lines that contain the exclamation mark at the end of the line in the given text.
Text:
This is exciting!
Wow, that's impressive!
No excitement here
Good job!
Write a regular expression to match any sequence of one or more digits in the given text.
Text: "There are 42 students in the class, and the answer is 7."
Write a regular expression to match three consecutive digits in the given text.
Text: "The product key is 4555321."
Write a regular expression to match words that can be spelled with or without a trailing "u" (e.g., "color" or "colour") in the given text.
Text: "The color/colour of the sky is blue."
Write a regular expression to match words with three consecutive "x" characters in the given text.
Text: "The fox jumped over the foxx fence."
Write a regular expression to match repeated words (e.g., "the the") in the given text.
Text: "Yesterday the the cat chased the the mouse."
Write a regular expression to match phone numbers in the format "(123) 456-7890" that may or may not include parentheses around the area code.
Text: "Call (555) 123-4567 or 555-7890 for assistance."
Write a regular expression to match dates in the format "DD.MM.YYYY" with varying numbers of digits (e.g., "15.1.2023" or "5.12.23") in the given text.
Text: "The important dates are 15.1.2023 and 5.12.23."
Write a regular expression to match words with exactly three vowels in the given text.
Text: "The quiet cat slept peacefully."
Write a regular expression to match any sequence of "ab" characters repeated one or more times in the given text.
Text: "The pattern abababab is repeated."
Write a regular expression to match email addresses that contain a variable number of letters, digits, dots, and underscores, followed by the "@" symbol, and then a domain with a variable number of letters and dots.
Text: "Contact us at john.doe@example.com or jane_smith@email.co.uk."
Write a regular expression to match the names of either "Python" or "JavaScript" in the given text.
Text: "I enjoy programming in Python and JavaScript."
Write a regular expression to match colors "red," "blue," or "green" in the given text.
Text: "The flag can be red, blue, or green."
Write a regular expression to match any day of the week (Monday, Tuesday, Wednesday, etc.) in the given text.
Text: "The meeting is scheduled for Monday or Friday."
Write a regular expression to match files with either a ".jpg", ".jpeg" or ".png" extension in the given text.
Text: "Valid images formats are .jpg, .jpeg and .png files."
Write a regular expression to match phone numbers that start with either "(123)" or "(456)" in the given text.
Text: "Contact us at (123) 456-7890 or (456) 123-9876 for assistance."
Using the grep command, list all titles (lines that start with #) of the "regex-exercise.md" file.