Regular expressions are nothing more than a sequence or pattern of characters itself. They provide the foundation for pattern-matching functionality.
Using regular expression you can search a particular string inside a another string, you can replace one string by another string and you can split a string into many chunks.
The three most basic searches using regular expressions are searching for the strings start, the strings end, or for characters it contains. We can do these using the following symbols:
^ indicates the string starts with the specified characters, so “^foo” would match any string starting with “foo”. This would match “foo is nice” or “foo the laws” but would not match “out and foo”.
$ indicates that a string finishes with the specified characters, so “foo$” would match any string that ended with “foo”. This what match “What is it foo” or “Out and foo” but would not match “foo is nice”
“foo” looks for the characters specified within the quotes, anywhere within the string. This means not only would it match “foo is nice” and “out and foo” it would match “Something foo told”
“^foo$” This would match only strings that both start and end with foo, which applies to a the word “foo”.
^ specifies the beginning of the line.
$ specifies the end of the line.
foo The string “foo”
^foo “foo” at the start of a line
foo$ “foo” at the end of a line
^foo$ “foo” when it is alone on a line