# Question Solved1 Answer 2. Validating Strings with RegEx Given a list of strings made up of the characters 'a' and 'b', create a regular expression that will match strings that begin and end with the same letter. Example ' $$a$$ ', ' $$a a^{\prime}$$, and 'bababbb' match. ' $$a b$$ 'and ' $$b a b a$$ ' do not match. Replacing the blank (i.e., " ") with a regular expression 2. Validating Strings with RegEx Given a list of strings made up of the characters 'a' and 'b', create a regular expression that will match strings that begin and end with the same letter. Example ' a ', ' aa′, and 'bababbb' match. ' ab 'and ' baba ' do not match. Replacing the blank (i.e., " ") with a regular expression that matches strings as described. Locked code in the editor prints True for each correct match and False for each incorrect match. Constraints - 1≤ query ≤103 - 1≤∣ string ∣≤103 - Each character string[i] ∈{a,b} Sample Input STDIN Function 5→ number of strings to be tested, query =5 a → query Strings = ' a ', ' b ', 'ab', 'ba', 'aba' b ab ba aba Sample Output True True False False True Explanation The following query =5 validations are performed: 1. ' a ' starts and ends with ' a ', so it matches. 2. ' b ' starts and ends with ' b ', so it matches. 3. 'ab' starts with ' a ' but ends with ' b ', so it does not match. 4. 'ba'starts with ' b ' but ends with ' a ', so it does not match. 5. 'aba'starts and ends with ' a ', so it matches. Language Java 8 (i) -9.: (3) (2) : 1> import java. io. *; . . 11

LE2IRF The Asker · Computer Science

Transcribed Image Text: 2. Validating Strings with RegEx Given a list of strings made up of the characters 'a' and 'b', create a regular expression that will match strings that begin and end with the same letter. Example ' a ', ' aa′, and 'bababbb' match. ' ab 'and ' baba ' do not match. Replacing the blank (i.e., " ") with a regular expression that matches strings as described. Locked code in the editor prints True for each correct match and False for each incorrect match. Constraints - 1≤ query ≤103 - 1≤∣ string ∣≤103 - Each character string[i] ∈{a,b} Sample Input STDIN Function 5→ number of strings to be tested, query =5 a → query Strings = ' a ', ' b ', 'ab', 'ba', 'aba' b ab ba aba Sample Output True True False False True Explanation The following query =5 validations are performed: 1. ' a ' starts and ends with ' a ', so it matches. 2. ' b ' starts and ends with ' b ', so it matches. 3. 'ab' starts with ' a ' but ends with ' b ', so it does not match. 4. 'ba'starts with ' b ' but ends with ' a ', so it does not match. 5. 'aba'starts and ends with ' a ', so it matches. Language Java 8 (i) -9.: (3) (2) : 1> import java. io. *; . . 11
More
Transcribed Image Text: 2. Validating Strings with RegEx Given a list of strings made up of the characters 'a' and 'b', create a regular expression that will match strings that begin and end with the same letter. Example ' a ', ' aa′, and 'bababbb' match. ' ab 'and ' baba ' do not match. Replacing the blank (i.e., " ") with a regular expression that matches strings as described. Locked code in the editor prints True for each correct match and False for each incorrect match. Constraints - 1≤ query ≤103 - 1≤∣ string ∣≤103 - Each character string[i] ∈{a,b} Sample Input STDIN Function 5→ number of strings to be tested, query =5 a → query Strings = ' a ', ' b ', 'ab', 'ba', 'aba' b ab ba aba Sample Output True True False False True Explanation The following query =5 validations are performed: 1. ' a ' starts and ends with ' a ', so it matches. 2. ' b ' starts and ends with ' b ', so it matches. 3. 'ab' starts with ' a ' but ends with ' b ', so it does not match. 4. 'ba'starts with ' b ' but ends with ' a ', so it does not match. 5. 'aba'starts and ends with ' a ', so it matches. Language Java 8 (i) -9.: (3) (2) : 1> import java. io. *; . . 11