I am trying to learn Regular Expressions. I’ve looked at several tutorials but I did not find them
clear or comprehensive. My questions is when is ^$ used and when is “\b .” used? I know what they
mean but just are sure how.
Some examples:
1. \((\d+)\)\.\((\d+)\)\.\((\d+)\)
2. \b1?264[)- ]*\d{3}[- ]*\d{4}\b
3. ^[a-g]{4}$
Don’t all Regular Expressions have to start with “^” and end with “$” ?
Before seeing when they are used, first you need to know what they mean:
^is a start of line anchor.$is an end-of-line of line anchor.\bmatches a word boundary. In other words, it matches between a word character\wand either a non-word character\Wor the start or end of the string.For example:
^\d.\d$.foouse\bfoo\b. Omitting the word boundaries would cause it to match words that containfoosuch asseafood.