diff --git a/Userland/Libraries/LibRegex/RegexParser.cpp b/Userland/Libraries/LibRegex/RegexParser.cpp index ef35382831..91c42e5173 100644 --- a/Userland/Libraries/LibRegex/RegexParser.cpp +++ b/Userland/Libraries/LibRegex/RegexParser.cpp @@ -516,6 +516,20 @@ bool PosixBasicParser::parse_one_char_or_collation_element(ByteCode& bytecode, s return true; } + // Dollars are special if at the end of a pattern. + if (match(TokenType::Dollar)) { + consume(); + + // If we are at the end of a pattern, emit an end check instruction. + if (match(TokenType::Eof)) { + bytecode.empend((ByteCodeValueType)OpCodeId::CheckEnd); + return true; + } + + // We are not at the end of the string, so we should roll back and continue as normal. + back(2); + } + // None of these are special in BRE. if (match(TokenType::Char) || match(TokenType::Questionmark) || match(TokenType::RightParen) || match(TokenType::HyphenMinus) || match(TokenType::Circumflex) || match(TokenType::RightCurly) || match(TokenType::Comma) || match(TokenType::Colon)