Lesson

Match Beginning String Patterns, Regex Tutorials

Lesson Summary

In this regex tutorial, we look at a way of matching a string pattern on the beginning of the string pattern. In the past, we used the caret character to create a negated character set pattern in a string. Outside a character set, the caret character is used to find patterns at the beginning of a string. Learning the different functions and different meanings for the caret character is important or else we might not get the results we are looking for. In order to match the beginning of a string pattern, we use the caret character at the beginning of our pattern. For example, if we want to find out if the pattern "Ricky" is found at the beginning of a string, we would create the regex "/^Ricky/". If we then tested a string that begins with the pattern "'Ricky", our regex would return true. Understanding that the caret character is used differently depending on its placement within a regex, is important in using it correctly and therefore matching the pattern you wish to find.

Subscribe To Monthly Newsletter. Chance to Win Monthly Prizes

* indicates required


Share: