Question

In: Computer Science

QUESTION: Write regular expressions after the ► to validate the following inputs: a) Product codes that...

QUESTION:

Write regular expressions after the ► to validate the following inputs:

a) Product codes that have one or more letters followed by one or more digits.

b) Nonnegative integers between 1,000 and 9,999, including the comma.

c) Canadian zip code containing upper case characters only.

d) License plate numbers that have the form:

         Letter

         Digit

         Letter

         Hypen (-)

         Digit

         Letter

         Digit

Solutions

Expert Solution

Regular expressions in different laguages are similar expect the minor syntaxes.

a) Product codes that have one or more letters followed by one or more digits.

"\^[a-zA-Z][0-9]\" :

Explanation: The product code should be like first one or more letters and followed by one or more numbers. First must be letter so, We have written a-z and A-Z letters can be smaller or capitals. then followed by numbers 0-9.

b) Nonnegative integers between 1,000 and 9,999, including the comma.

"\^[123456789][,][0-9][0-9][0-9]\"

Explanation: Here We cannot give directly as 1000-9999 in square brackets. We can only give range 0-9, so with these the first digit should be 1 - 9 so we have taken this. then followed by a , then next three digits can be any between 0-9.

c) Canadian zip code containing upper case characters only.

"\^[0-9A-Z]{2,}\"

Explanation: Canadian Zip code may consits numbers. And all letters must be capital so. We have taken 0-9 for any number and A-Z for capital letters. And I am assuming the postal code at least has 2 characters of length so you can change this accordingly.

d) License plate numbers that have the form:

         Letter

         Digit

         Letter

         Hypen (-)

         Digit

         Letter

         Digit

"\^[a-zA-Z][0-9][a-zA-Z][-][0-9][a-zA-Z][0-9]\"

Explanation: As said above a-z and A-Z in square brackets indicates letter and a 0-9 indicates a digit.


Related Solutions

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)
Linux regular expressions: file name: lab3test.txt Create regular expressions that meet the following criteria. You may...
Linux regular expressions: file name: lab3test.txt Create regular expressions that meet the following criteria. You may use grep or egrep to answer these questions. 1.Match any lines that contain a phone number with the format 222-222-2222.
linux Regular expressions file name: lab3test.txt Create regular expressions that meet the following criteria. You may...
linux Regular expressions file name: lab3test.txt Create regular expressions that meet the following criteria. You may use grep or egrep to answer these questions. 1.Display all lines where the employee’s age is greater than 40 years old. Again, don’t think of this as a number, think of it as a series of characters.
Write regular expressions that describes the following language: The language over {0,1,/} that contains all and...
Write regular expressions that describes the following language: The language over {0,1,/} that contains all and only the strings that are base-2 (as above, you can use base-10 if you prefer) representations of rational numbers. Define a representation of a rational number to be either a representation of an integer, or two representations of integers separated by “/”. Leading 0s are allowed this time.
Write regular expressions that describes the following language: The language over {0,1} that contains all and...
Write regular expressions that describes the following language: The language over {0,1} that contains all and only the strings that are base-2 representations of odd positive integers. Do not allow leading 0s. (If you are more comfortable writing bulky regular expressions than you are working in base-2, you may write a regular expression for strings that are base-10 representations of odd integers without leading 0s, using alphabet {0,1,2,3,4,5,6,7,8,9}.)
Write a program to validate Canadian Postal Codes. A postal code must follow the pattern of...
Write a program to validate Canadian Postal Codes. A postal code must follow the pattern of L9L9L9 where: L is a letter 9 is a digit Your program should continue accepting postal codes until the user enters the word “exit”. Sample run (user input is shown in bold underline): Enter a postal code: T2T-3X7 Postal code wrong length, format L9L9L9 Enter a postal code: T2T3AA Postal code has letters where there are supposed to be digits Enter a postal code:...
Write a regular expressions that would match lines in text that contain word DATE: at the...
Write a regular expressions that would match lines in text that contain word DATE: at the beginning of a line followed by actual date in format YYYY-MM-DD. Space between colon ( : ) and date may or may not exist. In C, if you issue the following statement n << 2 where n is an integer, what will be value of n? In bash, if you define variable var = “date” and issue a statement echo `$var`, what output will...
Write a regular expressions that would match lines in text that contain word DATE: at the...
Write a regular expressions that would match lines in text that contain word DATE: at the beginning of a line followed by actual date in format YYYY-MM-DD. Space between colon ( : ) and date may or may not exist. In C, if you issue the following statement n << 2 where n is an integer, what will be value of n?
Describe the languages specified by the following regular expressions: 1. \\(_+)/ 2. (\(740\)...-...)|(...-...) (The alphabet is...
Describe the languages specified by the following regular expressions: 1. \\(_+)/ 2. (\(740\)...-...)|(...-...) (The alphabet is {1,2,3,4,5,6,7,8,9,0})
Write the balanced chemical reactions for the dissolution reactions AND the corresponding solubility product expressions for...
Write the balanced chemical reactions for the dissolution reactions AND the corresponding solubility product expressions for each of the following solids. Lastly, please calculate the solubility of each compound in pure water ignoring any acid-base properties. a. Fe(OH)3 b. CuS c. CaF2
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT