Regex or Regular Expression is a pattern language in order to define different character patterns. Regex 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]$
Start and End Of Line – ^ $
Another popular use case for the regex end of the line character is using with 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 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]*$