DA0-002 · Question #91
A data analyst receives the following sales data for a convenience store: The analyst needs to provide information on the products that contain chocolate. Which of the following RegEx should the analy
The correct answer is B. Chocolate$. To filter products that end with the word "Chocolate", the regular expression Chocolate$ is the correct choice, as the dollar sign signifies the end of a string.
Question
A data analyst receives the following sales data for a convenience store:
The analyst needs to provide information on the products that contain chocolate. Which of the following RegEx should the analyst use to filter the chocolate products?
Exhibit
Options
- AChocolate!
- BChocolate$
- C%Chocolate&
- D#Chocolate#$
How the community answered
(20 responses)- A5% (1)
- B80% (16)
- C10% (2)
- D5% (1)
Why each option
To filter products that end with the word "Chocolate", the regular expression `Chocolate$` is the correct choice, as the dollar sign signifies the end of a string.
`!` is a literal character in many RegEx implementations and does not have a special meaning for string ending.
In regular expressions, the dollar sign `$` is an an anchor that matches the end of the string. Therefore, `Chocolate$` will find strings that end precisely with "Chocolate", which would be appropriate if the goal is to match products where "Chocolate" is the last word.
`%` and `&` are not standard RegEx metacharacters for anchoring the end of a string; they are often used as wildcards in SQL LIKE clauses, not RegEx.
`#` is a literal character in RegEx and does not serve as a special anchor for string ending.
Concept tested: Regular expression anchors - end of string
Source: https://learn.microsoft.com/en-us/dotnet/standard/base-types/regular-expression-language-quick-reference#character-escapes
Topics
Community Discussion
No community discussion yet for this question.
