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:
- /([^aeiou])(.*)/
- /^([aeiou])(.*)/
or - /^([^aeiou])(.*)/
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:
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.
regex101.com is a really convenient tool for breaking down the parts of your pattern.
What is the use of the parentheses?
Parentheses in a regular expression usually indicate a ‘capture group’, or subset of the string to be stored for later reference. For example:
/^([aeiouy])(.)/
indicates a string starting with a single vowel (the first capture group is a single vowel), followed by any single character (the second capture group is any single character). How they get referenced elsewhere in the regex… Isn’t happening in this one.
Thanks for the reply.