c $ matches c in abc, while a $ does not match at all.Ī regex that consists solely of an anchor can only find zero-length matches. Similarly, $ matches right after the last character in the string. See below for the inside view of the regex engine. ^ b does not match abc at all, because the b cannot be matched right after the start of the string, matched by ^. The caret ^ matches the position before the first character in the string. They can be used to “anchor” the regex match at a certain position. Instead, they match a position before, after, or between characters. Putting one of these in a regex tells the regex engine to try to match a single character.Īnchors are a different breed. Thus far, we have learned about literal characters, character classes, and the dot. Start of String and End of String Anchors
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |