# 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?

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?

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

What will be the result when non greedy repetition is used on the pattern /a+?b/? (a) Matches ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
If the probability of occurrence of an event is p then the probability of non-happening of this event is Select the correct answer from above options...
Write pseudo code to count occurrence of a given number in the list. For example, consider the following list, if ... in the list. Select the correct answer from above options...
An experiment has 10 equally likely outcomes. Let A and B be two non-empty events of the experiment. If A consists of ... D. 5 or 10. Select the correct answer from above options...
An experiment has 10 equally likely outcomes. Let A and B be two non-empty events of the experiment. If A consists of ... 8 D. 5 or 10 Select the correct answer from above options...
In the circuit given below, bulb X uses 48 W when lit, bulb Y uses 22 W when lit and bulb Z uses 14. ... Questions for GATE EC Exam, Network Theory MCQ (Multiple Choice Questions)...
From a group of 3 boys and 2 girls, we select two children. What would be the sample space for this experiment ? Select the correct answer from above options...
What would be the behaviour if this() and super() used in a method? (a) Runtime error (b) ... java programming questions and answers pdf, java interview questions for beginners...