Question

In: Computer Science

Question d) Write the regular expression statement that will match a string that starts with the...

Question d) Write the regular expression statement that will match a string that starts with the word "Warning" following by one space and then a number of any number of digits.

Question e) Write the regular expression statement that will match a string that ends with the phrase "End of Report.

Question f) Write the regular expression statement that will match a string that starts with the phrase "Begin Log:" then contains a collection of characters (other than newline) followed by the phrase "End Log".


Question g) Write the regular expression statement that will match the string "Mr.", "Ms." or "Mrs." followed by one or more spaces, followed by one uppercase character then one or more lowercase characters.

Question h) Write the regular expression statement that will match a 10 digit phone number of the format (555-555-5555 or 5555555555 or 555-5555555). We want the pattern to allow an optional dash after the first 3 numbers and after the next three numbers.

Hint use the ? operator.

Solutions

Expert Solution

As per the guidelines ansering only the 4 questions.

d) The below regular expression will fetch as per the requirements. ^ stands for the start of the string. $ stands for the end of the string. [0-9]+ stands for a number between 0-9 any number of times. Please not that the termination character $ is not given at the end of the regular expression, which means this will do a partial match also. for example it will match "Warning 34" and "Warning 34isthis". Please put a $ sign at the end of the below expression if partial match is not required.

^Warning [0-9]+

e) The below regular expression will fetch the details. The ".+" at the beginning takes care of atleast 1 character in the start. The $ at the end takes care of the string ending with "End of Report".

.+End of Report$

f) The below regular expression will help fetching the details. The ".+?" in the middle takkes care of collection of characters in the middle of the string. The ? is a lazy macthing and that will help if more than 1 line exists in the input in the same pattern.

^Begin Log:.+?End Log$

g) The below will take care of the requirement. The pattern (Mr|Ms|Mrs) handles any of the given. The \\. stands for matching a dot character after the given .

(Mr|Ms|Mrs)\\. +[A-Z][a-z]+


Related Solutions

Q1 Write a python regular expression to match a certain pattern of phone number.             ###...
Q1 Write a python regular expression to match a certain pattern of phone number.             ### Suppose we want to recognize phone numbers with or without hyphens. The ### regular expression you give should work for any number of groups of any (non- ### empty) size, separated by 1 hyphen. Each group is [0-9]+. ### Hint: Accept "5" but not "-6" ### FSM for TELEPHONE NUMBER IS: # state:1 --[0-9]--> state:2 # state:2 --[0-9]--> state:4 # state:2 --[\-]---> state:3 #...
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.
Given a String variable address, write a String expression consisting of the string "http://" concatenated with...
Given a String variable address, write a String expression consisting of the string "http://" concatenated with the variable's String value. So, if the variable refers to "www.turingscraft.com", the value of the expression would be "http://www.turingscraft.com". in java
a) Given a variable word that has been assigned a string value,write a string expression...
a) Given a variable word that has been assigned a string value, write a string expression that parenthesizes the value of word. So, if word contains "sadly", the value of the expression would be the string "(sadly)"b) Assume that price is an integer variable whose value is the price (in US currency) in cents of an item. Write a statement that prints the value of price in the form "X dollars and Y cents" on a line by itself. So,...
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)
Regular expression translation [ac7]b[bc] Translation: Match any 1 character in a set that is either a,...
Regular expression translation [ac7]b[bc] Translation: Match any 1 character in a set that is either a, c, or 7, then a b, then any 1 character that is in a set that is either b or c. Match example: abc ^…$ \<the\> ^[A-Z]..$ ^[A-Z][ a-z]*3[0-5] [a-z]*\.$ ^ *[A-Z][a-z][a-z]$ ^[A-Za-z]*[^,][A-Za-z]*$ [[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3} .*\([0-9][.][0-9]\) [0-9]{3}-[0-9]{4}
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...
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?
Write an 8088/8086 assembly program that counts the length of a null terminated string that starts...
Write an 8088/8086 assembly program that counts the length of a null terminated string that starts at location STR.Assume string length will not exceed 255 character.Print the result on the screen?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT