Can someone confirm my understanding of the different uses for ^ please.
/[^aeiou]
/
- This checks if string contains anything EXCEPT a, e, i, o, u.
/^[aeiou]/
- This checks if string contains anything EXCEPT “aeiou”.
/^aeiou/
- This checks if string BEGINS with “aeiou”.
Thanks.
Here’s a post taken from stackOverflow
^ 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
Anywhere else -> start of string / line.
So ^[b-d]t$
means:
Start of line
b/c/d character
t character
End of line