Tutorial 5: Regular Expressions in Python — Using regex characters ‘ ^ $ \b \B’

Photo by Ilya Pavlov on Unsplash

Missed previous tutorial? — Click here

You can directly navigate to the topic of your interest by clicking on topic name given below :

1. Caret symbol ‘ ^ ’

2. Dollar symbol ‘ $ ’

3. Combination of ‘ ^ ’ and ‘ $ ’

4. word boundary — ‘ \b ’

5.not word boundary — ‘ \B ’

1. Caret symbol ‘ ^ ’

a) This matches with the position not character. It is used to match the start of the string.

b) It is used to match the beginning of each line when text has multiple lines with newline if the multiline flag is enabled.

More about flags — check Tutorial 7

c) It is also used with [ ] to match a negated set. For example, [^abcd] will match any character except ‘a’, ‘b’, ‘c’ or ‘d’.

2. Dollar symbol ‘ $ ’

a) This matches with the position not character. It is used to match the end of the string.

b) It is used to match the end of last line when text has multiple lines with newline if the multiline flag is enabled.

More about flags — check Tutorial 7

3. Combination of ‘ ^ ’ and ‘ $ ’

This matches with start and end i.e. entire string when correct regex code is written between ‘^’ and ‘$’ .

4. word boundary — ‘ \b ’

Word boundary is indicated by whitespace or a non-alphanumeric character.

5. not word boundary — ‘ \B ’

Not word boundary is indicated by a alphanumeric character.

Combination of \b and \B:

Do not worry about remembering all these things just understand the meaning of word (or not word) boundary and whenever you have problem try experimenting with few examples. Even I do the same things.

This is quite a task you completed today. Great work !!!

Take a deep breathe and move to the next tutorial. You can find next tutorial link in the comment box.

Happy learning !!!

--

--

--

I am a keen learner and diligent teacher with special interest in mathematics and machine learning.

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

Recommended from Medium

Serverless Architecture | ATeam Soft Solutions

Google Analytics 4: Migrating From Universal Analytics (GA4)

One day you’re questioning what on earth will ever make you feel happy and fulfilled.

Qualities of an agile development team

A Story of Simple Storage Service (AWS S3)

Local Storage

Understanding Memory Layout…..

How to Get n Largest or Smallest Elements in a List in Python

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
Gaurav Patil

Gaurav Patil

I am a keen learner and diligent teacher with special interest in mathematics and machine learning.

More from Medium

Tutorial 5 : OOPs in Python — Encapsulation

12 Dictionary Methods in Python to Help You Easily Access and Manipulate Data

Class in Python : All you need to know

Install Python 3 on Microsoft Windows