A. Regex is case-sensitive, so 'world' does not match 'World'.
B. Missing replacement string in gsub.
C. Syntax error due to missing parentheses.
D. gsub cannot be used with regex.
Solution
Step 1: Check regex matching
The regex /world/ is lowercase and Ruby regex is case-sensitive by default.
Step 2: Compare with string content
The string has "World" with uppercase W, so the regex does not match anything.
Final Answer:
Regex is case-sensitive, so 'world' does not match 'World'. -> Option A
Quick Check:
Case sensitivity causes no match [OK]
Hint: Remember regex is case-sensitive unless flagged [OK]
Common Mistakes:
Assuming regex matches ignore case by default
Thinking gsub needs parentheses around arguments
Believing gsub can't use regex
5. Given the string data = "User: John_Doe, Email: john@example.com", which gsub call will replace all non-alphanumeric characters (except underscore) with a dash "-"?
hard
A. data.gsub(/[\w]/, "-")
B. data.gsub(/\w/, "-")
C. data.gsub(/[^a-zA-Z0-9]/, "-")
D. data.gsub(/[^a-zA-Z0-9_]/, "-")
Solution
Step 1: Understand character classes
\w matches letters, digits, and underscore. \W matches anything not in \w.