In regular expressions, what does the ? quantifier indicate?

Prepare for the Red Hat Certified Systems Admin Exam EX200. Enhance your skills with interactive quizzes, flashcards, and detailed explanations. Ace your certification exam today!

Multiple Choice

In regular expressions, what does the ? quantifier indicate?

Explanation:
The ? after a character or group makes that element optional, meaning it can appear either zero or one time in the match. This lets patterns accept both possibilities. For example, colou?r matches both color and colour because the u is optional. Similarly, ab? can match a or ab. This is distinct from other quantifiers: + requires one or more occurrences, * allows zero or more, and the dot is a wildcard that matches a single character (not a quantifier itself). The ? can also influence quantifiers to be non-greedy when used after them, but in its basic form it signals optional presence.

The ? after a character or group makes that element optional, meaning it can appear either zero or one time in the match. This lets patterns accept both possibilities. For example, colou?r matches both color and colour because the u is optional. Similarly, ab? can match a or ab. This is distinct from other quantifiers: + requires one or more occurrences, * allows zero or more, and the dot is a wildcard that matches a single character (not a quantifier itself). The ? can also influence quantifiers to be non-greedy when used after them, but in its basic form it signals optional presence.

Subscribe

Get the latest from Passetra

You can unsubscribe at any time. Read our privacy policy