nerdexam
LPI

101-400 · Question #411

When using regular expressions, which of the following characters match the beginning of a line?

The correct answer is A. ^. See the full explanation below for the reasoning.

Question

When using regular expressions, which of the following characters match the beginning of a line?

Options

  • A^
  • B?
  • C
  • D
  • E$

How the community answered

(42 responses)
  • A
    79% (33)
  • B
    2% (1)
  • C
    12% (5)
  • D
    5% (2)
  • E
    2% (1)

Community Discussion

5
Viktor S.Viktor S.Apr 14, 2026

A is correct, full stop. The caret anchors a pattern to the start of a line, so something like ^error only matches if "error" appears at the very beginning, not buried in the middle. The other four are quantifiers or a different anchor: question mark means zero or one, asterisk means zero or more, plus means one or more, and dollar is the end-of-line anchor, the mirror image of caret. Confusing caret with the others is a sign you memorized a chart instead of thinking about what anchoring even means, so burn this into your head now before it bites you on a real grep command at 2am.

15
Samuel O.Samuel O.Apr 19, 2026

Does your regex engine treat ^ differently in multiline mode versus single-line, or are you just memorizing A for the exam?

2
Wesley A.Wesley A.Apr 21, 2026

Real distinction worth knowing cold, and I would add that confusing ^ with \A trips people up just as often because \A always anchors to the absolute start of the string no matter what flags you set, so if the exam gives you a multiline pattern and asks what \A matches, the answer is never "each line."

0
Wesley A.Wesley A.Apr 5, 2026

C for sure, the asterisk anchors you right to line start.

0
Viktor S.Viktor S.Apr 5, 2026

Wesley, the asterisk means zero or more of the preceding character, it does not anchor anything, that is what the caret does, so A is the correct pick here.

0
Full 101-400 Practice