Practice Top 30 Python Programming Questions on Regular Expressions
Q1. Check if the string "hello" contains the pattern "ell".
Input: hello
Expected Output: Match found: ell.
Q2. Find all the digits in the string "abc123xyz456".
Input: abc123xyz456
Expected Output: ['123', '456'].
Q3. Extract all words from the string "This is regex 101!".
Input: This is regex 101!
Expected Output: ['This', 'is', 'regex', '101'].
Q4. Check if the string starts with "Hello".
Input: Hello, World!
Expected Output: Match found: Hello.
Q5. Check if the string ends with "World".
Input: Hello, World!
Expected Output: Match found: World.
Q6. Find all sequences of repeated "a" in "aaa b aa aaa".
Input: aaa b aa aaa
Expected Output: ['aaa', 'aa', 'aaa'].
Q7. Find all sequences of 3 characters in "abcdef".
Input: abcdef
Expected Output: ['abc', 'bcd', 'cde', 'def'].
Q8. Match "python" in "Python is fun" (case-insensitive).
Input: Python is fun
Expected Output: Match found: Python.
Q9. Find all vowels in the string "Regular expressions".
Input: Regular expressions
Expected Output: ['e', 'u', 'a', 'e', 'e', 'i', 'o'].
Q10. Find all special characters in "Hello@2024!#".
Input: Hello@2024!#
Expected Output: ['@', '!', '#'].
Q11. Find the first occurrence of "regex" in the string "Learning regex is fun!".
Input: Learning regex is fun!
Expected Output: Match found: regex.
Q12. Find all occurrences of "is" in "This is a test. Is it working?".
Input: This is a test. Is it working?
Expected Output: ['is', 'Is'].
Q13. Find all words starting with "t" in "This is a test text".
Input: This is a test text
Expected Output: ['This', 'test', 'text'].
Q14. Find all numbers in the string "The price is 100 and 50".
Input: The price is 100 and 50
Expected Output: ['100', '50'].
Q15. Verify if "user@example.com" is in a valid email format.
Input: user@example.com
Expected Output: Valid email.
Q16. Replace all digits in "abc123xyz" with #.
Input: abc123xyz
Expected Output: abc###xyz.
Q17. Replace "cat" with "dog" in "The cat is cute".
Input: The cat is cute
Expected Output: The dog is cute.
Q18. Replace all vowels in "regex" with .
Input: regex
Expected Output: rgx.
Q19. Remove all special characters from "Hello@2024!#".
Input: Hello@2024!#
Expected Output: Hello2024.
Q20. Replace all spaces in "Python is fun" with _.
Input: Python is fun
Expected Output: Python_is_fun.
Q21. Split the string "a,b,c" by commas.
Input: a,b,c
Expected Output: ['a', 'b', 'c'].
Q22. Split the string "This is regex" by spaces.
Input: This is regex
Expected Output: ['This', 'is', 'regex'].
Q23. Split "a;b,c d" by ;, ,, or space.
Input: a;b,c d
Expected Output: ['a', 'b', 'c', 'd'].
Q24. Split "one1two2three" by digits.
Input: one1two2three
Expected Output: ['one', 'two', 'three'].
Q25. Split "python" by vowels.
Input: python
Expected Output: ['p', 'th', 'n'].
Q26. Count the occurrences of "the" in "The the the cat".
Input: The the the cat
Expected Output: 3.
Q27. Extract phone numbers from "Call me at 123-456-7890 or 987-654-3210".
Input: Call me at 123-456-7890 or 987-654-3210
Expected Output: ['123-456-7890', '987-654-3210'].
Q28. Check if the password "P@ssw0rd" contains at least one digit, one special character, and one uppercase letter.
Input: P@ssw0rd
Expected Output: Valid password.
Q29. Extract all HTML tags from "
Hello
".
Input:
Hello
Expected Output: ['
', '
', '
', '
'].
Q30. Find all valid IPv4 addresses in "192.168.0.1, 10.0.0.256".
Input: 192.168.0.1, 10.0.0.256
Expected Output: ['192.168.0.1'].
Bikki Singh
Hi, I am the instructor of TechnoVlogs. I have a strong love for programming and enjoy teaching through practical examples. I made this site to help people improve their coding skills by solving real-world problems. With years of experience, my goal is to make learning programming easy and fun for everyone. Let's learn and grow together!