Question

In: Computer Science

For each of the strings below, does the pattern [^O]*o+ match the string? If so, list...

For each of the strings below, does the pattern [^O]*o+ match the string? If so, list which part of the string will be matched. If not, then state "no match". (a) balloons (b) FOODY (c) bookstore (d) "Look" (e) PoolRoOM

Solutions

Expert Solution

Firstly let us break down the pattern [^O]*o+ for more understanding of which part of the strings which be matched.

[^O] - This part is telling us to stop matching the strings once they contain O in it.

[^O]* - It is just a character class repeating itself for zero or more consecutive occurrences.

o+ - This part will only match the strings that have at least o in it.

So, the pattern [^O]*o+ will only match those strings that are having at least one o in it and will match up to the last occurrence of o in the string to be matched and not starting with O. Where ever O will occur, the pattern would stop matching. So the word FOODY will not be matched by the pattern.

balloons - the string will get matched up to balloo. Here's a screenshot of the code verifying the same.

FOODY - This word will get no match. Hence 'No match' is the answer. Since the word does not contain even a single o.

The array which we get as a result of word.match is null that is we did not get any matches.

bookstore - Since the text will get matched up to the last occurrence of o. So the answer here would be booksto.

"Look" - Since the text will get matched up to the last occurrence of o. So the answer here would be "Loo.

PoolRoOM - Since the text will get matched up to the last occurrence of o and the string will stop matching once we get even a single occurrence of O. So the answer here would be PoolRo.

​​​​​​​

Let me know if you have any issues.

Thank you.

​​​​​​​Have a good day.


Related Solutions

Java:    Find a pattern that will match any string that is --  at least 6 characters...
Java:    Find a pattern that will match any string that is --  at least 6 characters long, -- and begins with a letter or number (\w) -- and contains at least one non-letter and non-number (\W).
Write a program that removes a target item (a string) from a list of strings, and...
Write a program that removes a target item (a string) from a list of strings, and that will print out the list without the item. Do not use built-in functions other than input, print, and append. Instead, you may generate a new list that does not include the target item and you can use the append() function. Your program should read two inputs: the target and the list. For example, if the input is “apple” and the list is [‘berry’,...
1.3. Match the terms in the list to the definitions below. Each term may be used...
1.3. Match the terms in the list to the definitions below. Each term may be used only once. (1 point per question; 10 points total) A.    Translation                                                             F.    Local currency B.    Restatement                                                           G.   Functional currency C.    Temporal method                                                   H.    Translation gain or loss D.    Current rate method                                               I.     FASB ASC subtopic 830-30 E.    Reporting currency                                                 J.    Cumulative translation adjustment _____ 1.        The currency of the country in which the company is domiciled _____ 2.        Changing FC to the currency of...
Below is a list of examples of benefits that ecosystems provide to people. Match each benefit...
Below is a list of examples of benefits that ecosystems provide to people. Match each benefit with the correct category of ecosystem services. A. Regulating services B. Provisioning services C. Supporting services D. Cultural services selectABCD 1. Before Europeans came, Michigan had a large area of old growth beech-maple forest near its southern border. Except for a small area where the loggers ate lunch, the entire beech-maple forest ecosystem was logged in the 1800’s. Only the loggers’ picnic area remains...
Why does pumping strings in a CFL changes two parts of the string simultaneously?
Why does pumping strings in a CFL changes two parts of the string simultaneously?
Given the nested collection that maps each term to a set of strings   Return a string...
Given the nested collection that maps each term to a set of strings   Return a string of terms that are repeated in all the nested sets Given : {apple=[apple BALL carrot, ball !carrot! ,!Dog*&]} {apple=[apple BALL carrot, ball !carrot! ,!Dog*&], dog=[ball !carrot! ,!Dog*&]} Return: [ball !carrot! ,!Dog*&] Public static String common(Map<String, Set<Sting>> map) { }
a. Define a function less of type (String, List) -> List so that less(e, L) is...
a. Define a function less of type (String, List) -> List so that less(e, L) is a list of all the strings in L that are shorter than e. b. Define a function more of type (String, List) -> List so that more(e, L) is a list of all the strings in L that are longer than e. c. Replace the above functions with a function compare of type (String, List, (String, String) -> Boolean) such that depending on the...
since firstN is a string it can't compare to an ArrayList * list so how am i suppose to write these parts comparing the string to the list[mid]
c++ question:int ArrayList::binarySearchID(string firstN) const{   int first = 0;         int last = length - 1;         int mid = (first + last) / 2;   bool found = false;   int index;   while (!found && last >= first)   {       if (firstN == list[mid])       {           found = true;       }       else if (firstN > list[mid])       {           first = mid - 1;       }       else if (firstN < list[mid])       {           last...
Using the Boyer-Moore algorithm, find the Bad Match table for the below patterns. Pattern1: AABCACCCA Pattern...
Using the Boyer-Moore algorithm, find the Bad Match table for the below patterns. Pattern1: AABCACCCA Pattern 2: CCCAAABBD Pattern3: ABCABCBAD Pattern4: BSDGSBAA
Write a Python loop that goes through the list and prints each string where the string...
Write a Python loop that goes through the list and prints each string where the string length is three or more and the first and last characters of the strings are the same. Test your code on the following three versions of the list examples: examples = ['abab', 'xyz', 'aa', 'x', 'bcb'] examples = ['', 'x', 'xy', 'xyx', 'xx'] examples = ['aaa', 'be', 'abc', 'hello'].
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT