Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Regular Expression for Salaries. How is the Python regular expression look like for this question? + Detailed explanation, thanks. After successfully implementing the famous FizzBuzz

Regular Expression for Salaries.

How is the Python regular expression look like for this question? + Detailed explanation, thanks.

image text in transcribed image text in transcribed

After successfully implementing the famous FizzBuzz task, Jeffrey started waiting for a job offer from a big software company. As he is very serious about his employment, the only kinds of messages that he wants to read are exact salary proposals payed in: US Dollars (USD) Canadian Dollars (CAD) or Great British Pounds (GBP). He needs your help in filtering the messages that he is interested in. Help him by writing an appropriate regular expression. The message should consist of: currency abbreviation ("USD", "CAD" or "GBP"), exactly one space character, the non-negative value in the format described below. The value can be an integer (e.g. 10) or it can have a fractional part, in which case we allow exactly two digits after the dot (e.g. 0.10). Additionally, the integer part must be in a convenient format: starting from the end, each group of three digits must be separated with a comma (e.g. 1,123,412). Leading zeros in the integer part are not allowed. Example test cases: "GBP 1,123" "USD 0.10" "GBP 1,123,412" "CAD 10.00" "CAD 10" "ABC 10" "AUSD 10" should not match (too many spaces) should match should match should match should match should not match (wrong currency) should not match (redundant characters Example test cases: "GBP 1,123" should not match (too many spaces) "USD 0.10" should match "GBP 1,123,412" should match "CAD 10.00" should match "CAD 10" should match "ABC 10" should not match (wrong currency) "qUSD 10" should not match (redundant characters at the beginning) "USD 100' should not match (redundant characters at the end) "CAD 10.1231" should not match (fractional part too long) "USD 012.12" should not match (redundant leading zero) You can assume the input string will not contain newlines. Your regular expression will be evaluated using Python's re.search. Do not write any code other than the expression; for example, to match a string containing a digit, your solution should be \d (without quotes or surrounding the expression by slashes)

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_2

Step: 3

blur-text-image_3

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

Database 101

Authors: Guy Kawasaki

1st Edition

0938151525, 978-0938151524

More Books

Students also viewed these Databases questions

Question

What do Dimensions represent in OLAP Cubes?

Answered: 1 week ago