At times, the pattern to be matched appears at either the very beginning or end of a string. In these cases, use a caret "^" to match a desired pattern at the beginning of a string, and a dollar sign "$" for the end of the string. For example, the regular expression email matches anywhere along the following strings: "email", "emailing", "bogus_emails", and "smithsemailaddress". However, the regex ^email only matches the strings "email" and "emailing". The caret "^" in this example is used to effectively anchor the match to the start of the string. For this reason, both the caret "^" and dollar sign "$" are referred to as anchors in the regex syntax.
Example 1: Use "$" to match the ".com" pattern at the end of a string.
.*\.com$
mydomain.com a.b.c.com
mydomain.org mydomain.com.org
Example 2: Use "^" to match "inter" at the beginning of a string, "$" to match "ion" at the end of a string, and ".*" to match any number of characters within the string.
^inter.*ion$
internationalization internalization
reinternationalization
Example 3: Use "^" inside parentheses to match "To" and "From" at the beginning of the string.
(^To:|^From:)(Smith|Chan)
From:Chan To:Smith From:Smith To:Chan
From: Chan from:Smith To Chan
Example 4: Performing the same search as #3, place the caret "^" outside the parentheses this time for similar results.
^(From|Subject|Date):(Smith|Chan|Today)
From:Smith Subject:Chan Date:Today
X-Subject: date:Today