From 1fa0fa7786f815cf2d11e9f6bfee615e85fcaefb Mon Sep 17 00:00:00 2001 From: Amey Joshi Date: Mon, 25 Dec 2017 00:19:53 -0500 Subject: [PATCH] #103 Add greedy vs lazy matching (#104) --- README.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/README.md b/README.md index 29f1d4c..82add6e 100644 --- a/README.md +++ b/README.md @@ -540,6 +540,23 @@ at the end of each line in a string. [Test the regular expression](https://regex101.com/r/E88WE2/1) +## 6. Greedy vs lazy matching +By default regex will do greedy matching , means it will match as long as +possible. we can use `?` to match in lazy way means as short as possible + +
+"/(.*at)/" => The fat cat sat on the mat. 
+ + +[Test the regular expression](https://regex101.com/r/AyAdgJ/1) + +
+"/(.*?at)/" => The fat cat sat on the mat. 
+ + +[Test the regular expression](https://regex101.com/r/AyAdgJ/2) + + ## Contribution * Report issues