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 that matches strings as described. Locked code in the editor prints True for each correct match and False for each incorrect match. Constraints - \( 1 \leq \) query \( \leq 10^{3} \) - \( 1 \leq \mid \) string \( \mid \leq 10^{3} \) - Each character string[i] \( \in\{a, b\} \)
Sample Input STDIN Function \( 5 \rightarrow \) number of strings to be tested, query \( =5 \) a \( \rightarrow \) 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