What is Regular Expression?
It is used for Pattern Matching
How to write Regular expressions
- search for the occurrence of complete text
<text>
## sample ###
Microsoft & Linux are the popluar operating systems
To search operating
reg => operating
- Searching for beginning of the line
Microsoft is commercial OS.
Most popular Desktop Os is from Microsoft
Linux is opensource os.
Most popular Server Os is from Linux
Regex for lines which begin with Linux
^Linux
- Searching for the end of the line
Microsoft is commercial OS.
Most popular Desktop Os is from Microsoft
Linux is opensource os.
Most popular Server Os is from Linux
Regex for lines ending with Linux
Linux$
- Searching for any character with word combinations
msoft
softm
nsofty
ysoftn
Regex for the lines with 1 character before soft
^.soft
Regex for the lines with 1 character before soft and ends there
^.soft$
- Repetition using {}
- Grouping using ()
Exercise
- Create a file with following content
linux is an os. Linux is opensource.
you can choose between different distributions of Linux such debian, redhat.
Linux is inspired from Unix.
Linux can be alternative to unix and windows
linux is also considerd as nix platform where linux, unix are part of it.
Posix is a popular format.
- search for all the occurrences of Linux irrespective of case
- Display the count of occurrences of Linux & Linux and both the cases
- Show the line number where windows is present
- Display all the lines which do not have windows
- Write a regular expression to search for nix or unix or Posix