Regular Expression Matching for 100.$ Pattern
Short answer
CD The regex 100.$ matches strings starting with '100', followed by exactly one character, and ending immediately, fitting 1001 and 1000.
Question
Key Takeaways
The trap lies in ignoring the single-character constraint of the dot (.) metacharacter combined with the end-of-string anchor ($), leading candidates to incorrectly select longer or shorter strings.
This page explains how to evaluate the regular expression 100.$ against numeric sequences. Correct options are C and D because they fit the pattern of '100' plus one additional character.
Common mistake: Selecting A (10000) is a common error where users assume the dot matches multiple trailing digits, failing to recognize that the dollar sign anchors the match strictly after one character.
Expert Analysis
The question asks which number sequences match the regular expression 100.$. To determine the correct answers, we must analyze the components of this regex pattern.
The literal characters 1, 0, and 0 indicate that any matching string must start with "100". The character . is a special metacharacter in regular expressions that matches exactly one instance of any character (except newline in some modes, but typically any single character in basic contexts). The anchor $ asserts the position at the end of the string. Therefore, the entire pattern requires a string that starts with "100", followed by exactly one arbitrary character, and then ends immediately.
Let's evaluate each option against these constraints:
- A. 10000: This string has five digits. It starts with "100", but it is followed by two more zeros (
00). Since the regex allows only one character after "100" before the end of the string, this sequence is too long and does not match. - B. 100: This string has three digits. It matches the initial
100, but there are no characters following it to satisfy the.requirement. The regex expects one more character before the end of the string, so this is too short and does not match. - C. 1001: This string has four digits. It starts with "100", followed by the digit
1(which satisfies the.wildcard), and then the string ends (satisfying$). This fits the pattern perfectly. - D. 1000: This string has four digits. It starts with "100", followed by the digit
0(which satisfies the.wildcard), and then the string ends. This also fits the pattern perfectly.
Common mistakes often involve misunderstanding the scope of the . metacharacter or the role of the $ anchor. Some might think . matches multiple digits or forget that the string must terminate immediately after the single matched character. However, strict adherence to the regex definition confirms that only strings of length 4 starting with "100" will match.
Exam Strategy
When solving regex questions, break down the pattern into its atomic components: literals, wildcards, and anchors. Always verify the total length of the candidate string against the fixed characters and the count of variable characters allowed. For multi-select questions, test every option rigorously against the specific constraints rather than relying on intuition about similar-looking patterns.
Frequently Asked Questions
What does the dot (.) mean in regular expressions?
Why doesn't 100 match the pattern 100.$?
Community Votes
50% of anonymous learners picked answer C. Votes are pick records left by other test-takers — they are not the verified answer.
Discussion 1 contributions
Compiled from public community threads and reader submissions, lightly edited for clarity. Handles and vote tallies are shown as recorded, and comments reflect the views of individual contributors.
From public community threads 1
-
Savvyxx 👍 1Only C & D
Reader comments & corrections
No reader corrections yet — spotted an error or have a note? Share it below.