Regex or Regular Expression is a pattern language in order to define different character patterns. Regex is mainly used to find and match a given pattern or select a pattern value from a text or string. The end of the line (EOL) is one of the most popular patterns which is used to specify the end of the line.
End Of Line – $
The end of the line is expressed with the dollar sign ($) in the regex. The end of the line will be put at the end of the regex pattern and the required pattern will be specified before the $ sign. The end of the line character is generally used to “line ends with a word, character, characters set, number, etc.”.
# the last character will be wisetut
t$
# The last word will be wisetut
wisetut$
# The line will end with uppercase chracters
[A-Z]$
# The line will end with lowercase chracters
[a-z]$
Grep End Of Line Regex Example
The grep
command is a very useful tool to search file contents in different ways. The regex end of line can be searched for file contents using the grep. The -e
option is used to enable regex for the grep.
$ grep -e "wisetut$" notes.txt

Online Tool End Of Line Regex Example
Different online tools can be used to match the end of the line like below.
wisetut$

Start and End Of Line – ^ $
Another popular use case for the regex end of the line character is using with the start of the line character. The start of the line character is ^ in regex. We can use the start of the line and end of the line characters in order to set the complete line pattern.
# The line only contain the word "wisetut"
^wisetut$
# The line starts and ends with "wisetut"
^wisetut.*wisetut$
# The line starts with numbers and ends with letters
^[0-9]*.*[a-Z]*$