Specifically when does ^
mean "match start" and when does it mean "not the following" in regular expressions?
From the Wikipedia article and other references, I've concluded it means the former at the start and the latter when used with brackets, but how does the program handle the case where the caret is at the start and at a bracket? What does, say, ^[b-d]t$
match?
^
only means "not the following" when inside and at the start of []
, so [^...]
.
When it's inside []
but not at the start, it means the actual ^
character.
When it's escaped (\^
), it also means the actual ^
character.
In all other cases it means start of the string / line (which one is language / setting dependent).
So in short:
[^abc]
-> not a, b or c [ab^cd]
-> a, b, ^ (character), c or d\^
-> a ^
character So ^[b-d]t$
means: