Menu

[Solved] 2 Task Write Python File Called Regexpy Detines Several Variables Containing Compiled Regu Q37199018

Hello! Please help me with this problem.Thank you so much!
2. Task Write a python file called regex.py that detines several variables containing compiled regular expressions, as followdef full match(regex, text) Gives a list of all complete matches ans- for match in regex.finditer(text): ans.append (match-g4. Troubleshooting For nospace, negative character classes (i.e., beginning ) are your friend. For quotation, youll probably2. Task Write a python file called regex.py that detines several variables containing compiled regular expressions, as follows: e nospace -a regular expression that matches one or more non-whitespace characters. There is a relatively straightlorward solution that is 12 characters long CS1110-001/smile should match, as should hi there should not match, nor should the empty string. e quotation a regular expression that matches text beginning and ending with a ,with no internal ,where the first and last character inside the quotes are not spaces. Our reference solution is 32 characters long “hi there should match -hi there. should not match, nor should”hi there . or I said “h just now twonum -a regular expression that matches pairs of numbers, separated by a space, comma, or both (with the space after the comma if both:, but not ).Acoept both numbers with and without decimal places, and allow an optional preceding on each number. If there is a decimal place, there must be at least one digit on each side of it Our reference solution is 50 characters long Additionally, each of the two numbers (with the- if present) should be a group after a match. 3,4,3.0, 4.5, and-3.14159265 1110 should all match. 3.4.5, 1,1 2, and 3 4 should not match. 3. Testing your code When you run regex.py, nothing should happen. It defined variables, it does not define functions or run anything. If in another file you enter the following import regex Cs1110-001/smile 1 hi there “hi there- but not . hi there. or ·hi there . or I said “hi” just now 3,4, 3.0, 4.5 and -3.14159265 1110 but not 3.4.S 1 or 1 2 or 3 – Thomas Jefferson and Edmund Jennings Randolph and J. Plerpont Finch and 7. Jefferson but not 7 Jefferson or Thomas J.or Flannery O’Co def full natch(regex, text) lete matches def full match(regex, text) Gives a list of all complete matches” ans- for match in regex.finditer(text): ans.append (match-group(o)) return ans ns-ful1 match(regex.nospace, text) print(‘nospace: C$1110-001/smile’ in ns in ns hi there’ not in ns, not in ns) q-full mateh (regex.quotation, text) print(‘quotations hi therein g ·’hi there.. not in q, “hi there ot in q “I said hi just now not in g) tn ful1 mateh(regex. twonum, text) print( twonum: 3,4 in tn, 3.0 4.5* in tn -3.14159265 1110 in tn, 3-4.5, 1 not in tn 12 not in tn, 3-4not in tn) for match in regex.twonum.finditer(text): İf match.group(0)– “J,4.1 print matchl:. 3in match.groups) 4 in match.groups if match.group(0)3.14159265 1110 print( match2: “3.14159265 in match groupsO 1110* in match.groupsO then that file, when run, should print al true: nospace: True True True True quotation: True True True True vonum: True True True True True rue matehl: True True match2: True True 4. Troubleshooting For nospace, negative character classes (i.e., beginning ) are your friend. For quotation, youll probably include most of nospace twice (for the first and last non-white character), but also exclude quotes “. Also, you might want to handle the special case of a quote with zero or one non-white characters inside specially. For twonum, you probably want to get a single number matcher working, and a gap (comma, or, space, or comma space) working, and then combine them into “number gap number”. “Whitespace characters” includes space but also newlines n and r and tabs t The “should be in a group” constraint can be met by adding parentheses… pythex is your friend. If you are not sure what your regex are doing, try playing with them there. Show transcribed image text 2. Task Write a python file called regex.py that detines several variables containing compiled regular expressions, as follows: e nospace -a regular expression that matches one or more non-whitespace characters. There is a relatively straightlorward solution that is 12 characters long CS1110-001/smile should match, as should hi there should not match, nor should the empty string. e quotation a regular expression that matches text beginning and ending with a ,with no internal ,where the first and last character inside the quotes are not spaces. Our reference solution is 32 characters long “hi there should match -hi there. should not match, nor should”hi there . or I said “h just now twonum -a regular expression that matches pairs of numbers, separated by a space, comma, or both (with the space after the comma if both:, but not ).Acoept both numbers with and without decimal places, and allow an optional preceding on each number. If there is a decimal place, there must be at least one digit on each side of it Our reference solution is 50 characters long Additionally, each of the two numbers (with the- if present) should be a group after a match. 3,4,3.0, 4.5, and-3.14159265 1110 should all match. 3.4.5, 1,1 2, and 3 4 should not match. 3. Testing your code When you run regex.py, nothing should happen. It defined variables, it does not define functions or run anything. If in another file you enter the following import regex Cs1110-001/smile 1 hi there “hi there- but not . hi there. or ·hi there . or I said “hi” just now 3,4, 3.0, 4.5 and -3.14159265 1110 but not 3.4.S 1 or 1 2 or 3 – Thomas Jefferson and Edmund Jennings Randolph and J. Plerpont Finch and 7. Jefferson but not 7 Jefferson or Thomas J.or Flannery O’Co def full natch(regex, text) lete matches
def full match(regex, text) Gives a list of all complete matches” ans- for match in regex.finditer(text): ans.append (match-group(o)) return ans ns-ful1 match(regex.nospace, text) print(‘nospace: C$1110-001/smile’ in ns in ns hi there’ not in ns, not in ns) q-full mateh (regex.quotation, text) print(‘quotations hi therein g ·’hi there.. not in q, “hi there ot in q “I said hi just now not in g) tn ful1 mateh(regex. twonum, text) print( twonum: 3,4 in tn, 3.0 4.5* in tn -3.14159265 1110 in tn, 3-4.5, 1 not in tn 12 not in tn, 3-4not in tn) for match in regex.twonum.finditer(text): İf match.group(0)– “J,4.1 print matchl:. 3in match.groups) 4 in match.groups if match.group(0)3.14159265 1110 print( match2: “3.14159265 in match groupsO 1110* in match.groupsO then that file, when run, should print al true: nospace: True True True True quotation: True True True True vonum: True True True True True rue matehl: True True match2: True True
4. Troubleshooting For nospace, negative character classes (i.e., beginning ) are your friend. For quotation, youll probably include most of nospace twice (for the first and last non-white character), but also exclude quotes “. Also, you might want to handle the special case of a quote with zero or one non-white characters inside specially. For twonum, you probably want to get a single number matcher working, and a gap (comma, or, space, or comma space) working, and then combine them into “number gap number”. “Whitespace characters” includes space but also newlines n and r and tabs t The “should be in a group” constraint can be met by adding parentheses… pythex is your friend. If you are not sure what your regex are doing, try playing with them there.

Expert Answer


Answer to 2. Task Write a python file called regex.py that detines several variables containing compiled regular expressions, as f… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *