Question

In: Statistics and Probability

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/

Solutions

Expert Solution

ANSWER:

a.)

  • Given expession: /^[a-z][0-9]*\.$/
  • Let's break down each component of this expression
  • ^[a-z] : The string starts with a lower case alphabet
  • [0-9]*: Followed by zero or more digits
  • \.$ : Ends with a dot.
  • Example : a0934.
  • The string starts with a lower case alphabet , Followed by zero or more digits and ends with a dot

b.)

  • Given expression: /([0-9]+)\s\w+\s\1/
  • Let's break down each component of this expression
  • ([0-9]+): Contains one or more digits continously. This is called group 1
  • \s : Followed by one white space
  • \w+ : Followed by one or more ascii letter, digit or underscore
  • \s: Followed by a while space
  • \1: Followed by contents of group 1, that is , one or more digits continously
  • Example : 345 _s3 48238
  • This string Contains one or more digits continously, Followed by one white space,  Followed by one or more ascii letter, digit or underscore, Followed by a while space and finally Followed by one or more digits continously

(OR) TRY THIS

a) Strings that start with a lower case alphabet followed by any number of optional digits

Example
d123

b) 1/more digits (number) followed by a space followed by 1/more alphabets or digits or underscores followed by a space followed by exact same number that it is starting with

Example
91509 abc 91509

NOTE:: I hope this answer is helpfull to you......**Please support me with your rating

**Please give me"LIKE".....Its very important for me......THANK YOU


Related Solutions

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...
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.
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 '#'
Write a regular expression, using the regular expression syntax used by lex, that matches any finite...
Write a regular expression, using the regular expression syntax used by lex, that matches any finite decimal representation of a nonnegative real number.
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)
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 '('.
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...
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. Define a regular expression for validating each of the following: a. A U.S. zip code,...
1. Define a regular expression for validating each of the following: a. A U.S. zip code, which must have five digits, followed by an optional hyphen and four digits. b. A telephone number in the format (aaa) nnn-nnnn, where aaa represents the area code and the ns represent digits. c. A date in the form of day-month-year, where the month is a three-letter code and the year is four digits. A hyphen must separate the day and month and year...
: Create a Java program that will accept a regular expression and a filename for a...
: Create a Java program that will accept a regular expression and a filename for a text file. The program will process the file, looking at every line to find matches for the regular expression and display them. Regular Expression Format : The following operators need to be accepted: + - one or more of the following character (no groups) * - zero or more of the following character (no groups) [] – no negation, no character spans – the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT