Explain the uses of caret(^) in regex

Explain the uses of caret(^) in regex
0

#1

Continuing the discussion from freeCodeCamp Algorithm Challenge Guide: Pig Latin:

Please explain the uses of ^ (caret)
what does it match using the caret at different places like these:

  1. /([^aeiou])(.*)/
  2. /^([aeiou])(.*)/
    or
  3. /^([^aeiou])(.*)/

#2

The caret serves two different purposes. It is a special character that denotes “the beginning of a line” and it is a “not” operator inside of []s.

  1. Matches any character that is not a vowel followed by any number of characters.
  2. Matches a vowel at the start of a line, followed by any number of characrters.
  3. Matches any character that is not a vowel, at the start of a line, followed by any number of characters.

regex101.com is a really convenient tool for breaking down the parts of your pattern.