in Technology by

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
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
0 votes
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...
asked Nov 28, 2021 in Education by JackTerrance
0 votes
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...
asked Nov 13, 2021 in Education by JackTerrance
0 votes
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...
asked Oct 26, 2021 in Education by JackTerrance
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...
asked Aug 2, 2022 in Education by JackTerrance
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...
asked Nov 29, 2021 in Education by JackTerrance
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...
asked Mar 22, 2021 in Technology by JackTerrance
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...
asked Dec 31, 2021 in Education by JackTerrance
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...
asked Jan 5, 2022 in Education by JackTerrance
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....
asked Aug 30, 2022 in Education by JackTerrance
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...
asked Nov 12, 2021 in Education by JackTerrance
...