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?

1 Answer

0 votes
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
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)...
0 votes
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...
0 votes
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...
0 votes
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...
0 votes
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...
0 votes
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)...
0 votes
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...
0 votes
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...
0 votes
if there was one thing in constitution you wish to change what would it be and why Select the correct answer from above options...
0 votes
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...
0 votes
If a student gains unauthorized access to the student database and modifies his/her marks, what type of violation would it be? (1)Confidentiality (2)Both the options (3)Integrity...
0 votes
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...
0 votes
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...
0 votes
If pattern is to be stored, then what does stable state should have updated value of? (a) current sate (b) next ... (d) none of the mentioned Please answer the above question....
0 votes
What will be the outcome, if the Prediction is Yes and it matches with the Reality? What ... proposed by,electromagnetic theory engineering physics,electromagnetic theory nptel...