Question

In: Computer Science

submit a regular expression that will identify each of the following patterns. 1 - a US...

submit a regular expression that will identify each of the following patterns.

1 - a US telephone number that conforms to the following pattern 111.222.3456

2 - a US social security number that fits the following pattern 111-22-3456

3 - an American Express credit card number that fits the following format:

      4 digits followed by a space followed by 6 digits followed by a space followed by 5 digits

False positives are allowed in each case, so all you need to do is find patterns that fit your Regular Expression.

Make sure you test the Regular Expression in Linux and submit a screenshot of the expression and result.

Solutions

Expert Solution

Hi,

For First Solution Regular Expression-

^[0-9][0-9][0-9][.][0-9][0-9][0-9][.][0-9][0-9][0-9][0-9]$

^ means it will start with the character here the succeding character is a digit. So it should start always with a digit.

[0-9] means any single digit. If we write again [0-9] then that means another single digit.

[.] means single character dot(.)

$ means the end of the expression. Here from the regular expression the last character shuld be a digit

For Second Solution Regular Expression-

^[0-9][0-9][0-9][-][0-9][0-9][-][0-9][0-9][0-9][0-9]$

^ means it will start with the character here the succeding character is a digit. So it should start always with a digit.

[0-9] means any single digit. If we write again [0-9] then that means another single digit.

[-] means single character hyphen(-)

$ means the end of the expression. Here from the regular expression the last character shuld be a digit

For Third Solution Regular Expression-

^[0-9][0-9][0-9][0-9][[:space:]][0-9][0-9][0-9][0-9][0-9][0-9][[:space:]][0-9][0-9][0-9][0-9][0-9]$

^ means it will start with the character here the succeding character is a digit. So it should start always with a digit.

[0-9] means any single digit. If we write again [0-9] then that means another single digit.

[[:space:]] means single character space( )

$ means the end of the expression. Here from the regular expression the last character shuld be a digit.

From below screenshot I have created a text file where there are seven combination of numbers including three combinations also I have mentioned which was mentioned in your question-

So from the below screenshot, I will use the above three regular expressions that will let us to find those three combination of expressions

As you can see from the above screenshot with the help of those three regular expressions I am able to find those three expressions.

First I am using cat for that file i.e, in my case text.txt and then doing a pipe(|) which will allow us to grep for that particular regular expression


Related Solutions

1. What is a regular expression? Write a regular expression that will detect “College” and “collegE”....
1. What is a regular expression? Write a regular expression that will detect “College” and “collegE”. 2. What is degree centrality? Create a graph of 4 vertices and compute the degree centrality of the vertices. 3. Compute internal and external community densities for a graph containing 6 nodes. You can create any graph of 6 nodes with at least 4 edges.
Regular Expressions Assignment Write a regular expression for each of the following. Can you show output...
Regular Expressions Assignment Write a regular expression for each of the following. Can you show output please. A blank line (may contain spaces) Postal abbreviation (2 letters) for State followed by a space and then the 5-digit zip code A KU student username (Ex. lpork247) A “valid” email address (also explain how you defined “valid”) A SSN pattern (ddd-dd-dddd)
Unix / Linux 16. Regular Expression: Given the following regular expression, provide a description of the...
Unix / Linux 16. Regular Expression: Given the following regular expression, provide a description of the intended match. ^[^A-Z] 17. Regular Expression: Given the following regular expression, provide a description of the intended match. [^^!] 18. Regular Expression: Given the following regular expression, provide a description of the intended match. ^.\{72\}$ 19. Regular Expression: Given the following regular expression, provide a description of the intended match. [A-Za-z0-9] 20. Regular Expression: Given the following regular expression, provide a description of the...
Understanding RegEx to identify patterns of data. 1. Create 4 regular expressions to filter a specific...
Understanding RegEx to identify patterns of data. 1. Create 4 regular expressions to filter a specific data set. 2. In addition to the description, provide two test cases that will pass the input and one that will fail
Formal Languages Give a regular expression for each of the following languages: L2a = {w ?...
Formal Languages Give a regular expression for each of the following languages: L2a = {w ? {0,1}* | w corresponds to the binary encoding of non-negative integers that are evenly divisible by 4 L2b = {w ? {a,b}* | w contains at least one 'a' and exactly two b's} L2c = {w ? {0, 1, 2}* | w starts with a 2, ends with a 1 and contains an even number of 0's}.
1. Which of the following conditions does not lead to a change in gene expression patterns...
1. Which of the following conditions does not lead to a change in gene expression patterns in bacteria cells? A. Sporulation B. Heat shock C. Nutrient availability D. Nitrogen deprivation E. None of the choices are correct 2. Predict the outcome of the removal of the N form the DNA sequence of the (lamda) phage: A. Lysogenic cycle will be induced B. Entry into the bacterial host will be blocked C. Antitermination will be affected D. Transcription form the left...
Consider the following regular expression meta operators: ( ) [ ] { } . * +...
Consider the following regular expression meta operators: ( ) [ ] { } . * + ? ^ $ | \ For each of the following, give one example of strings which the regular expression would match. Describe (colloquially, in a manner that a non-technical person would understand) the set of strings that the pattern is designed to match. Each regular expression is enclosed in the pair of '/' characters below. [2 marks each] (a) /^[a-z][0-9]*\.$/ (b) /([0-9]+)\s\w+\s\1/
Define a regular expression in JAVA for the following An "Ent" is an at sign '@',...
Define a regular expression in JAVA for the following An "Ent" is an at sign '@', followed by one or more decimal digits '0' through '9' or uppercase letters 'R' through 'W', followed by an octothorpe sign '#'
Understanding RegEx to identify patterns of data. Create 10 regular expressions to filter a specific data...
Understanding RegEx to identify patterns of data. Create 10 regular expressions to filter a specific data set and explain what they each do.
create a regular expression in Java that defines the following. A "Stir" is a right brace...
create a regular expression in Java that defines the following. A "Stir" is a right brace '}' followed by zero or more lowercase letters 'a' through 'z' and decimal digits '0' through '9', followed by a left parenthesis '('.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT