From b61216e39ed83cfd76fcf86daa1ea6148bc5615f Mon Sep 17 00:00:00 2001 From: Aakash Panchal <51417248+Aakash-Panchal27@users.noreply.github.com> Date: Sun, 8 Mar 2020 12:57:24 +0530 Subject: [PATCH] Create lazy_matching.html --- Akash Articles/RegEx/lazy_matching.html | 99 +++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 Akash Articles/RegEx/lazy_matching.html diff --git a/Akash Articles/RegEx/lazy_matching.html b/Akash Articles/RegEx/lazy_matching.html new file mode 100644 index 0000000..5e6b051 --- /dev/null +++ b/Akash Articles/RegEx/lazy_matching.html @@ -0,0 +1,99 @@ + + + + + + + + + + + + + +

Lazy matching:

+ +

As we have seen, the default nature of quantifiers is greedy, so it will match as many characters as possible.

+ +
+ +
+ +

To make it lazy, we use ? quantifier, which turns the regex engine to match as less characters as possible which satisfies the regex.

+ +
+ +
+ +

So, now we can match html tags as below:

+ +
+ +
+ +

Let's have one more example,

+ +
+ +
+ +

Problem

+ +

Find an expression to match href="url" in html file. Note that url can be anything, like https://xyz.com, http://abc.io/app, https://cde.org.

+ +

Answer: href=".*?"

+ +
+ +
+ +

We will see how to extract things(like, urls) from the text using regex, in the "group and capturing" concept.

+ + + + + +