Overview of lazy nature

You are familiar with greedy nature now. While sometimes we’ll need greedy Regex it may not be necessary. Consider the text (‘firstname’ ‘lastname’ ‘address’). Modify it a bit by removing space after “firstname” and before “lastname”. The modified text will be ‘firstname’‘lastname’ ‘address’. We will work on the same text discussed in the last lesson and derive its solution as well.

RegEx has one special character to handle its greedy nature. You have a global flag to control the eagerness of the RegEx. Similarly, the lazy character handles the greedy nature of RegEx.

Lazy characters

Get hands-on with 1200+ tech skills courses.