Sunday, 5 January 2020

Capturing zero or more characters in regex while being non-greedy

For regular expressions, it is often desirable to make part of the expression non-greedy. For this, we use the question mark.


What is the difference between (.*?) and (.*)? when used as part of a larger expression in order to capture zero or more characters?


For example, will: (.*?)ng ever yield a different result than (.*)?ng ?


The end results are the same (confirmed by https://regex101.com/), but are there differences that are not so obvious?

No comments:

Post a Comment

How can I VLOOKUP in multiple Excel documents?

I am trying to VLOOKUP reference data with around 400 seperate Excel files. Is it possible to do this in a quick way rather than doing it m...