# regmatches(number, gregexpr(pattern = “2.?2”,text = number)) Is this an example of non-greedy quantifier? If yes, then why and what would be the equivalent greedy quantifier?

0 votes
56 views

regmatches(number, gregexpr(pattern = “2.?2”,text = number)) Is this an example of non-greedy quantifier? If yes, then why and what would be the equivalent greedy quantifier?

## 1 Answer

0 votes
by (228k points)
No. This is an example of a non-greedy quantifier. An equivalent greedy approach would be –
regmatches(number, gregexpr(pattern = "2.*2",text = number)) .
Suppose that for a given number, val1 = 2020000200

The greedy approach would initiate from the first digit ‘2’. It then moves ahead and encounters the second digit ‘2’. It keeps searching for another ‘2’ digit which it also encounters. However, it does not find any more digits after that and hence, it returns the value: 20200002.

A non-greedy approach on the other hand, stops at the first match and returns us the value of 202.

## Related questions

0 votes
1 answer 31 views
0 votes
1 answer 37 views
0 votes
1 answer 58 views
0 votes
1 answer 73 views
0 votes
1 answer 146 views
0 votes
1 answer 132 views
0 votes
1 answer 42 views
0 votes
1 answer 33 views
0 votes
0 answers 13 views
0 votes
1 answer 28 views
0 votes
1 answer 50 views
0 votes
1 answer 44 views
0 votes
1 answer 6 views
0 votes
1 answer 28 views
0 votes
1 answer 24 views
0 votes
1 answer 19 views
0 votes
1 answer 14 views
0 votes
1 answer 39 views
0 votes
1 answer 19 views
0 votes
1 answer 25 views
0 votes
1 answer 33 views
0 votes
1 answer 64 views
0 votes
1 answer 284 views
0 votes
1 answer 48 views