How to learn RegEx

import re
target_str = "Jessa knows testing and machine learning"
res_str = re.sub(r"\s", "_", target_str)print(res_str) # Output 'Jessa_knows_testing_and_machine_learning'
RegExr was created by gski!@#$%^&*(), and is proudly hosted by Media Temple.Edit the Expression & Text to see matc!@#$%^&*()/_+hes. Roll over matches or the expression for details. PCRE & JavaScript / flavors of RegEx are suppoRegrted. Validate your expression with Tests mode.01. First 05. Fifth
02. Second 06. Sixth
03. Third 07. Seventh
04. Fourth 08. Eight

1. RegEx Syntax

1.1 Character Set

. => Means match any character (excluding new line) which includes all special characters, all character, all numeric, etc.\d => Means match any digit or numeric digit. Character set = [0-9]\w => Means match any word. Character set = [a-zA-Z_]\s => Means match any whitespace/space. Character set = [\ ].....for rest of the sets check documentation.....
RegExr online tool interface and character set

1.2 Count of findings to Search in character set

method 1
method 2

1.3 Prevent Character collision / confusion

regex collision / confusion

2. Flags in Regex

2.1 Global Flag

2.2 Multiline Flag

3. Anchors

  1. \b : Beginning of a word
  2. \B : Inside a word
  3. ^ : Start of a string
  4. $ : Ending of a string

3.1 Beginning of a word

example 1

3.2 Beginning of a string


3.3 Incorrect Searching (multiline)


3.4 Correct Searching (multiline)

For special symbols
for digits and numeric

4. Direct Search

RegEx are supported
direct search

Using regex in python3

import reFILEPATH="file1.txt"with open(FILEPATH) as file1:
pattern=r"\b(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}\b[^\.]"matches = re.finditer(pattern, data, re.MULTILINE)for matchNum, match in enumerate(matches, start=1):




Learner. Curious about Security

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Lecture 7(Manifolds) Replay

Baba Bulleh Shah Quotes || Pakistani Sufi Poet || Waliullah Saying || Urdu Quotes Lines

Public Chargers Far Less Reliable Than Previously Reported

Stay positive! It’s Another just challenge.

“If you want to know what God thinks of money, just look at the people he gave it to.”

8 Newest PICKUP TRUCKS For 2021~2022

Being an introvert is “not a flaw, it’s a gift”

“The person who doesn’t know where his next dollar is coming from usually doesn’t know where his…

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Takshil Patil

Takshil Patil

Learner. Curious about Security

More from Medium

Basic Web Technologies Knowledge required for starting with the web Exploitation Part 1

Jobs in Cybersecurity

Beginner's Guide to Becoming a Professional Bug Bounty Hunter

Hacking — How to start?