© Sanjib Sinha 2017

Sanjib Sinha, Beginning Ethical Hacking with Python, 10.1007/978-1-4842-2541-7_12

12. Regular Expressions

Sanjib Sinha

(1)Howrah, West Bengal, India

Searching and replacing with regular expressions is equally easy and very simple in nature. To do that we will tweak our old code a little bit. We use “re” module and it does the simple jobs. Regular expression is itself a big topic. We try to understand the basic things so that we can use it in our future projects.

Using “re” Module

If you want to use “re” module, the first step is importation. We need to import the module first and write it on the top of the code. Consider this code where we have a text file called “file.txt” and it is stored in our “primary” folder.

<code>#!/usr/bin/python3 ...

Get Beginning Ethical Hacking with Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.