Using Regular Expression.
1. Write the regular expression that matches any string that ends with a capital letter.
2. Write the regular expression that matches any string that begins with a digit, ends with a digit, and has AT MOST only one digit in the middle of the string. (* means zero or more of preceding, +means one or more and ? means 0 or 1 (we did not look at the ? in class))
So your answer should match
12 (begins and ends with a digit with nothing between)
2jfgkdjdlk5kjfdsdsj3 (begins and ends with a digit with one digit in middle)
345 (begins and ends with a digit with one digit in middle)
3ert5 (begins and ends with a digit with no digits in middle)
But does not match 3456 (too many digits) abds23 (does not start with a digit) etc.
1. Answer = .*[A-Z]
2. Answer = [0-9][^0-9]*[0-9][^0-9]*[0-9]
-> Starting with 0-9
-> [^0-9]* is for 0/more characters that are not digits
-> [0-9]? means 0/1 occurrence of a digit.
-> Ending with 0-9
Please up vote. Happy Learning!
Using Regular Expression. 1. Write the regular expression that matches any string that ends with a...
Write a PHP regular expression pattern that matches a string that satisfies the following description: The string must begin with the (uppercase) letter A. Any three alphanumeric characters must follow. After these, the letter B (uppercase or lowercase) must be repeated one or more times, and the string must end with two digits.
Write a regular expression that matches whole numbers, such as 34, and 8, as well as real numbers with two decimal digits, such as 100.99 and 3.56. Your regular expression will not match numbers with one decimal digits, such as 3.4 or more than two decimal digits, such as 3.555. Answer:
I. Write a regular expression that matches a string of bits only if: it starts with a '0', ends with a '00', and has a '1' between every '010'.
8.17 python a.) Write a regular expression pattern to match all words ending in s. b.) Write a regular expression pattern to match all words ending in ing. c.) Write a regular expression pattern to match all words with ss anywhere in the string. d.) Write a regular expression pattern to match all words beginning and ending with the letter a. e.) Write a regular expression pattern to match all the words that start with st. f.) Write a regular...
4. Write regular expressions that match the descriptions given below. (10 P Description A sequence of digits of any length that also contains the sequence of four letters "meow", in that order, anywhere in the Expression sequence. A sequence of zero or more x's and y's, OR zero or one z's. 3 The American word color, or the British spelling (colour). Your answer can NOT include an or. 4 A string that begins with an X and ends with an...
Question 6 10 pts For each regular expression below, fill in the table with an expression of length 5 which matches the expression and an expression of length 5 which does NOT match the expression. If any of these tasks is impossible, write "impossible" in the table and comment below. The alphabet for this problem is {0, 1, 2} Regular Expression String, length 5, which matches String, length 5, which does NOT match 0*((01112)* I (22)* ) * (012)*1 (20)*...
Preliminaries For this lab you will be working with regular expressions in Python. Various functions for working with regular expressions are available in the re module. Fortunately, Python makes it pretty easy to check if a string matches a particular pattern. At the top of the file we must import the re module: import re Then we can use the search() function to test whether a string matches a pattern. In the example below, the regular expression has been saved...
Write a regular expression pattern that matches familial relationships involving a mother, father, son, daughter, and the words Great, grand, and Step. To simplify the problem, we will use just the first letters (case is important) of these words with no spaces between them. The symbol GGgs means great great grandson. Legal: Should Match : m, gf, Ggm, GGgf, Ss,, SGgs, Illegal: Should Not Match: mf, Gm, SSm, GSm,
Write a regular expression that matches: a) all strings that end with a dot character ".", without the quotes. b) all strings that begin with a "#" character, without the quotes. c) all floating-point numbers using standard notation (e.g., 12.345 or –12.345). Note that matching numbers may contain any number of digits before or after the decimal point. d) all floating-point numbers using scientific notation (e.g., 1.234e+5 or –1.234E–5). Again, matching numbers may contain any number of digits before or...
Use the Python “re” module to do the following: 1. Write a regular expression pattern that matches string “March 1, 2019, Mar 1, 2019, March First, 2019, March First, 19”. No credit for not using special characters: “*,+,?, | and etc” to do the matching. 2. Write a regular expression pattern that matches strings representing trains. A single letter stands for each kind of car in a train: Engine, Caboose, Boxcar, Passenger car, and Dining car. There are four rules...