Question: The java question about regular expressions For this question, consider names of cities that are made from any number of words where the first letter
The java question about regular expressions

For this question, consider names of cities that are made from any number of words where the first letter is always in uppercase and the words are separated by a space. Implement a regular expression as a Java String p like so: String p = "*****************"; such that ***************** is a regular expression pattern that will match any String that contains the name of a city and only such strings. Your answer must include the whole line of code above, meaning that the ***************** must be properly backslash-escaped both in terms of backslash escapes required for regular expressions and any backslash escapes required to put the expression inside the quotes above. Your answer will be inserted automatically into a test method match() like so: public void match(String s){String p = "*********************"; System.out.println(s.match(p)? "match" + s: "does not match" + s);} the test cases will invoke this method. Example: The following are valid city names: Ho Chi Minh City Palmerston North Auckland The following are invalid city names: Sydney san Francisco New york For this question, consider names of cities that are made from any number of words where the first letter is always in uppercase and the words are separated by a space. Implement a regular expression as a Java String p like so: String p = "*****************"; such that ***************** is a regular expression pattern that will match any String that contains the name of a city and only such strings. Your answer must include the whole line of code above, meaning that the ***************** must be properly backslash-escaped both in terms of backslash escapes required for regular expressions and any backslash escapes required to put the expression inside the quotes above. Your answer will be inserted automatically into a test method match() like so: public void match(String s){String p = "*********************"; System.out.println(s.match(p)? "match" + s: "does not match" + s);} the test cases will invoke this method. Example: The following are valid city names: Ho Chi Minh City Palmerston North Auckland The following are invalid city names: Sydney san Francisco New york
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
