Question 1
What is the output of the following code?
import re
text = "The product code is XYZ123-456."
pattern = r"\b[A-Z0-9]+\b"
matches = re.findall(pattern, text)
print(matches)
Question 2
What is the output of the following code?
import re
text = "The Python version is 3.10."
pattern = r"\d\.\d+"
matches = re.findall(pattern, text)
print(matches)
Question 3
What is the output of the following code?
import re
text = "The URL is https://www.example.com."
pattern = r"https?://\w+\.\w+\.\w+"
match = re.search(pattern, text)
print(match.group())
Question 4
What will be the output of the following code?
import re
text = "The price of the product is $15.99."
pattern = r"\$\d+\.\d+"
match = re.search(pattern, text)
print(match.group())
Question 5
What will be the output of following code?
import re
text = "I have 2 apples and 3 bananas."
pattern = r"\d+"
matches = re.findall(pattern, text)
print(matches)
Question 6
What is the output of the following code?
import re
text = "The price is $19.95."
pattern = r"\$\d+\.\d{2}"
match = re.search(pattern, text)
print(match.group())
Question 7
What will be the output of following code?
import re
text = "The quick brown fox jumps over the lazy dog."
pattern = r"\b\w{4}\b"
matches = re.findall(pattern, text)
print(matches)
Question 8
What is the output of the following code?
import re
text = "The year 2023 is approaching."
pattern = r"\b\d{4}\b"
matches = re.findall(pattern, text)
print(matches)
Question 9
What will be the output of the following code?
import re
text = "Hello, World!"
pattern = r"[A-Z][a-z]+"
matches = re.findall(pattern, text)
print(matches)
Question 10
What will the output of the following code?
import re
text = "Email me at user123@example.com or call 555-123-4567."
pattern = r"\b\w+@\w+\.\w+\b|\d{3}-\d{3}-\d{4}"
matches = re.findall(pattern, text)
print(matches)