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
See Answer
Add Answer +20 Points
Community Answer
WTTSXQ
See all the answers with 1 Unlock
Get 4 Free Unlocks by registration

Step1/2.gkwtCW{margin:0;font-family:"Aspira Webfont","Helvetica","Arial",sans-serif;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column;gap:16px;}/*!sc*/data-styled.g356[id="sc-z3f5s1-0"]{content:"gkwtCW,"}/*!sc*/.iIwMoS{white-space:pre-wrap;}/*!sc*/data-styled.g358[id="sc-1aslxm9-0"]{content:"iIwMoS,"}/*!sc*/.fzJtOB{text-align:start;}/*!sc*/data-styled.g360[id="sc-1aslxm9-2"]{content:"fzJtOB,"}/*!sc*/.dAYptC{list-style:disc;padding:0;margin-left:1.5em;}/*!sc*/data-styled.g378[id="sc-1aslxm9-20"]{content:"dAYptC,"}/*!sc*/.FmsNR{margin:0;font-family:"Aspira Webfont","Helvetica","Arial",sans-serif;font-size:0.75rem;}/*!sc*/data-styled.g387[id="sc-9wsboo-0"]{content:"FmsNR,"}/*!sc*/.dereWD{margin:0;font-size:0.875rem;}/*!sc*/data-styled.g389[id="sc-1swtczx-0"]{content:"dereWD,"}/*!sc*/.dmyQem{margin:0;font-family:"Aspira Webfont","Helvetica","Arial",sans-serif;font-size:0.75rem;width:100%;text-align:center;}/*!sc*/data-styled.g413[id="sc-1uwiggj-0"]{content:"dmyQem,"}/*!sc*/.fwnwKl{max-width:70%;}/*!sc*/data-styled.g414[id="sc-1uwiggj-1"]{content:"fwnwKl,"}/*!sc*/.iHelzO{margin:0;font-family:"Aspira Webfont","Helvetica","Arial",sans-serif;line-height:normal;}/*!sc*/data-styled.g420[id="sc-1sugbjn-0"]{content:"iHelzO,"}/*!sc*/.kkKaFK{margin-top:14px;}/*!sc*/data-styled.g424[id="sc-1sugbjn-4"]{content:"kkKaFK,"}/*!sc*/.iQllJf{margin-top:14px;}/*!sc*/data-styled.g425[id="sc-1sugbjn-5"]{content:"iQllJf,"}/*!sc*// Here is your a ... See the full answer