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?
Using python, please do the following. 1. Write regular expressions. (a) Capture any string that contains...
Using python, please do the following. 1. Write regular expressions. (a) Capture any string that contains at least three digits. (b) Capture any word that starts with one lowercase character, and either ends with two digits or with three vowels. 2. Given the following statements: string = """ Supreme executive power derives from a mandate from the masses , not from some farcical aquatic ceremony .""" words = string . split () Write a short program, using the re module,...
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 Problem 1: Summing It Up Write a program, which takes two distinct integers separated by...
JAVA Problem 1: Summing It Up Write a program, which takes two distinct integers separated by space as input and prints the sum of all the integers between them, including the two given numbers. Note that the numbers can appear in either order. You may assume that both numbers are between –10, 000 and 10, 000. For example, if the input is as follows: 10 4 the output should be 49, since 10+9+8+7+6+5+4=49. Similarly, if the input is -3 10...
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...
Chapter 8: Searching, Extracting, and Archiving Data Exercise 8.a: Using grep, find, and regular expressions (Objective...
Chapter 8: Searching, Extracting, and Archiving Data Exercise 8.a: Using grep, find, and regular expressions (Objective 3.2) Linux Distribution: Fedora (non-root user & password needed) Desktop Environment: GNOME 3 1.   If you have not already done so, boot up your computer (or virtual machine) to start the Fedora Linux distribution. 2.   When the machine has booted up, access the tty2 virtual terminal by pressing Ctrl+Alt+F2. 3.   Log on to a regular user’s account by typing in the username at the...
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...
(1) What are the advantages and disadvantages to using the Int data type rather than the...
(1) What are the advantages and disadvantages to using the Int data type rather than the bool data type to manipulate Boolean expressions? Why do students think the int data type is still used for Boolean expressions? (2) Discuss how C++ provides two-way selection through the if....else statement. Explain the syntax of this statement. Also, explain how the bool data type is used in C++ to manipulate Boolean expressions.
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?
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT