Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Task 1: Pattern matching for strings Please find your answers to a through f . You will code these regular expressions in Python. a. An

Task 1: Pattern matching for strings

Please find your answers to a through f. You will code these regular expressions in Python.

a. An integer

b. A float consists of 1 or more digits before and after decimal pointc. A float with exactly 2 digits after the decimal point

d. A float end with letter f (4.321f)

e. Capital letters, followed by small case letters, followed by digits

f. Exactly 3 digits, followed by at least 2 letters

---------------------------------------------------------------------------------------------------------------

  1. Define 10 string variables such as follows. Notice some of them fit into multiple patterns while some others dont fit in any patterns.

22.11,23,66.7f, 123abcde,Case44, Happy,78, 66.7, yes123,Book111

  1. Write down the regular expressions for these patterns (you already have them from last weeks practice). We went over 3 re functions in last lecture (Check RegexInPython Example under week 3).

  1. For each test string, your code needs to find all matching patterns.

  1. Print out the results nicely formatted.

e.g.

22.11 matches the pattern: A float consists of 1 or more digits before and after decimal point.

22.11 matches the pattern: A float with exactly 2 digits after the decimal point

23 matches the pattern: An integer

yes123 doesnt match any patters.

----------------------------------------------------------------------------------------------

Task 2: Remove a part of a string

You can use the same .py file from task 1 to complete this question. Write a function that will find the int number at the beginning of a long string and remove it from the long string. Note that the integer might have space or no space following it. (Technical googling practice which function can you use to remove part of a string from a long string?)

Sample outputs:

Original sentence: 22 street

Found integer 22 at the beginning of this string, starting at index _ ending at index _. The rest of the string is: street.

Original sentence: 90years

Found integer 90 at the beginning of this string, starting at index _ ending at index _. The rest of the string is: years.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases Illuminated

Authors: Catherine Ricardo

2nd Edition

1449606008, 978-1449606008

More Books

Students also viewed these Databases questions

Question

Describe Balor method and give the chemical reaction.

Answered: 1 week ago

Question

How to prepare washing soda from common salt?

Answered: 1 week ago