Use the below step:
1. Define your pattern, do not for get to put '()' around the pattern.
2. Open the file.
3. Apply pattern on each line.
4. After reading the entire file heck '$1' variable, the last matched pattern will present in it.
For help use
this link.