nerdexam
CompTIA

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.

Data Acquisition and Preparation

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

DA0-002 question #91 exhibit

Options

  • AChocolate!
  • BChocolate$
  • C%Chocolate&
  • D#Chocolate#$

How the community answered

(20 responses)
  • A
    5% (1)
  • B
    80% (16)
  • C
    10% (2)
  • D
    5% (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.

AChocolate!

`!` is a literal character in many RegEx implementations and does not have a special meaning for string ending.

BChocolate$Correct

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.

C%Chocolate&

`%` 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.

D#Chocolate#$

`#` 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

#Regular Expressions#Data Filtering#Text Processing#Data Preparation

Community Discussion

No community discussion yet for this question.

Full DA0-002 Practice