# 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...
If a current of 0.5A flows through a metallic wire for 2 hours, then how many electrons would flow through the wire ? Select the correct answer from above options...
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...
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)...
write a program to enter a sentence and check if it contains palindrome words or not. if yes then count and ... present. Java class 10 Select the correct answer from above options...
A memory byte location contains the pattern 00101100. What does this pattern represent when interpreted as a binary ... ASCII code? Select the correct answer from above options...