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 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...
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...
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...
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...
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...
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...
ON PYTHON Exercise 1. For each of the relational/logical expressions listed in exercise1.py determine whether the...
ON PYTHON Exercise 1. For each of the relational/logical expressions listed in exercise1.py determine whether the expression evaluates to True or False. Place a comment after each expression with the truth value and submit the updated exercise1.py file to the dropbox. For example, x = 10 y = 11 x < y # True  insert a comment after the expression x = 10 y = 11 a = 12.5 b = -5.2 x < y # True x <...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT