What is a greedy regex?
Regarding this, how do I make a regex not greedy?
To make the quantifier non-greedy you simply follow it with a '?' the first 3 characters and then the following 'ab' is matched. greedy by appending a '?' symbol to them: *?, +?, ??, {n,m}?, and {n,}?.
Keeping this in view, what is greedy and non greedy in Python?
Python Regex Non-Greedy Match will match as few 'a' s as possible in your string 'aaaa' . Thus, it matches the first character 'a' and is done with it. In other words, the non-greedy quantifiers give you the shortest possible match from a given position in the string.
Regular expressions allow you to write a custom finite-state machine (FSM) in a compact way, to process a string of input. There are at least two reasons why using regular expressions is hard: The value of a regular expression isn't really to match valid input, it's to fail to match invalid input.