ACE-P-ALE1-04 practice question 35 of 35

Which character matches the end of a line in a regular expression?

Full set: 100 questions
Answer options
A: !
B: ^
C: $ Correct answer
D: ?
Correct Answer:
C. $
Explanation

In regular expressions, the dollar sign ($) is a metacharacter known as an anchor. It asserts a position at the very end of a line or string. It does not match any character itself but rather the position following the last character in the line. This is fundamental for creating patterns that must appear at the end of a line, a common requirement when filtering command output in network operating systems like Arista EOS.

Why Incorrect

A. !: The exclamation mark is not a standard metacharacter for matching the end of a line; it is used in more advanced constructs like negative lookaheads.
B. ^: The caret symbol is an anchor that matches the beginning of a line, which is the direct opposite of what is being asked.
D. ?: The question mark is a quantifier, indicating that the preceding character or group should appear zero or one time.

References

1. The Open Group Base Specifications Issue 7, 2018 edition (IEEE Std 1003.1-2017), Chapter 9, Regular Expressions, Section 9.3.6, "ERE Anchor Operators". This standard, which defines the behavior of tools like grep used in Arista EOS, states: "The ( '$' ) shall be an ERE anchor. The '$' shall match the end of the string..."

2. Arista Networks, EOS 4.31.1F Manual, Section: "Command-Line Interface", Subsection: "Filtering show Command Output". This documentation describes the use of the grep utility for filtering command output. The grep command implements the POSIX standard for regular expressions, where $ matches the end of a line.

3. MIT, "The Missing Semester of Your CS Education" Courseware (2020), Lecture 2: "Shell Tools and Scripting". The lecture notes on regular expressions explicitly state: "^ matches start of line, $ matches end of line". This confirms the standard usage of these anchors in a command-line context.

Scroll to Top