Question

RegEx (Regular Expressions) 1. Make 2 regular expressions to filter a specific data set in Java...

RegEx (Regular Expressions)

1. Make 2 regular expressions to filter a specific data set in Java and explain what they do.

2. In addition to the each regular expression, provide two test cases that will pass the input and one that will fail.

Homework Answers

Answer #1

Regular expressions with test cases :

1. ".a" - In this expression the dot can ne replaced by any single character . If more than one character replaces the dot then the string will be considered invalid.

Testcase :

(a) Pattern.matches(".a","xa") - valid string.

(b) Pattern.matches(".a","xa") - invalid because we need to replace the dot and the other charachter should remain in their own positions. But here the last character is changed to x which should be a.

(c) Pattern.matches(".a","xya") - invalid because we need to replace by only a single charcater.

2. "//D" - This regular expression checks for string with non-digit characters.

Testcase :

(a) Pattern.matches(".//D" ,"abc") - Valid as it only contains alphabets.

(b) Pattern.matches(".//D" ,"9AB") - This is invalid as it contains digit along with alphabets.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Data Set A- 7,7,7,9,9,9,10 Data Set B- 4,6,6,6,8,9,9,9,10,10,10 Step 1 Create a bar graph that examines...
Data Set A- 7,7,7,9,9,9,10 Data Set B- 4,6,6,6,8,9,9,9,10,10,10 Step 1 Create a bar graph that examines a variable or variables in your data set. Step 2 Find the sample mean, median (if it exists) mode for each set of data Next find the sample standard deviations for each set of data Create a box and whisker plot for each variable for each set data Eliminate any outliers from the samples. Redo part 1 for each variable (if necessary, if not...
1 The following are summary statistics for a set of data. Number of samples = 18,...
1 The following are summary statistics for a set of data. Number of samples = 18, sample average = 5.76, sample standard deviation = 0.493. At a 0.05 significance level is the population average less than 6? Show calculations and provide the proper statement with respect to the hypothesis and rejection or fail to reject. Which statistical distribution did you use to evaluate the test and why? Was this a one-tail test or a two-tail test?
Java Please [(1)] A palindrome is a string that reads the same forwards as backwards. Using...
Java Please [(1)] A palindrome is a string that reads the same forwards as backwards. Using only a fixed number of stacks and queues, the stack and queue ADT functions, and a fixed number of int and char variables, write an algorithm to determine if a string is a palindrome. Assume that the string is read from standard input one character at a time. The algorithm should output true or false as appropriate [(2)] Let Q be a non-empty queue,...
Java programming. 1) What, if anything, is wrong with the following Java code? void test(String x)...
Java programming. 1) What, if anything, is wrong with the following Java code? void test(String x) { switch (x) { case 1: break; case 2: break; case 0: break; default: break; case 4: break; } } Select one: a)Each case section must end with a break statement. b)The case label 0 must precede case label 1. c)There is nothing wrong with the Java code. d)The default label must be the last label in the switch statement. e)The variable x does...
Write a program in java that: 1. takes any number in any base between 2 and...
Write a program in java that: 1. takes any number in any base between 2 and 16 and converts it to base 10. 2. converts base 10 numbers to any given base between 2 & 16. The program should have a gui with an input box and two buttons, one button to convert any base between 2 and 16 to base 10; and one button to convert base 10 to any base between 2 and 16. **Please DO NOT upload...
Question 4 Write a regular expression that generates each of the following language constructs: (1) String...
Question 4 Write a regular expression that generates each of the following language constructs: (1) String constants with the following specifications: A string constant consists of any sequence of characters enclosed by the quotation marks: “ and ”       The sequence may be empty.                    The sequence cannot span multiple lines.       Don’t worry about escape characters (assume that they won’t appear in the input).       (2)  Multiple-line comment in C, C++ and JAVA with the following specifications:        The comment consists of any sequence...
Question 3 (5.5 marks = 1.5 + 1 + 2 + 1) The set of data...
Question 3 (5.5 marks = 1.5 + 1 + 2 + 1) The set of data below are from a sample of n = 7 7, -6, -3, 1, 9, 4, 7 a. Calculate the mean, median, and mode b. Calculate the range and range c. Calculate the variance and standard deviation d. Do your calculated values of the mean, median, and mode suggest that this distribution is symmetrical, negatively skewed or positively skewed? Please explain your answer in one...
Consider the following two sample data sets. Set​ 1: 99 22 77 55 88 Set​ 2:...
Consider the following two sample data sets. Set​ 1: 99 22 77 55 88 Set​ 2: 66 1313 1818 77 22 a. Calculate the coefficient of variation for each data set. b. Which data set has more​ variability? a. The coefficient of variation for set 1 is nothing​%. ​(Round to one decimal place as​ needed.) The coefficient of variation for set 2 is nothing​%. ​(Round to one decimal place as​ needed.) b. Which data set has more​ variability? Choose the...
18.0 65.5 24.3 11.9 7.6 52.8 78 What trends do you notice in your data set?...
18.0 65.5 24.3 11.9 7.6 52.8 78 What trends do you notice in your data set? Based on the trends and the history of your data set, make a claim. What kind of test (left, right, two tailed) would you have to complete? Explain the steps needed to complete the Hypothesis Test. What is needed?
Consider the following two sample data sets. Set 1: 4     5     7    6    8 Set 2:...
Consider the following two sample data sets. Set 1: 4     5     7    6    8 Set 2: 7    19   12    4    2 a. Calculate the coefficient of variation for each data set. b. Which data set has more​ variability?