Question

In: Computer Science

Create and test a python regular expression that matches a street address consisting of a number...

  1. Create and test a python regular expression that matches a street address consisting of a number with one or more digits followed by two words of one or more characters each. The tokens should be separated by one space each, as in 123 Main Street.

Solutions

Expert Solution

Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. If not, PLEASE let me know before you rate, I’ll help you fix whatever issues. Thanks

Note: Please maintain proper code spacing (indentation), just copy the code part and paste it in your compiler/IDE directly, no modifications required.

#code

import re

# pattern that matches a string with one or more digits followed by one space followed by one ore more 
# letters followed by a space followed by one ore more letters
pattern = "[0-9]+\s[A-Za-z]+\s[A-Za-z]+"

# creating a string containing multiple street addresses for testing
string = "123 Main Street is just around that road opposite to 455 Fifth Avenue. 85 Daimler St. is also there"

# finding and printing all street addresses found in string using pattern
print(re.findall(pattern, string))

#output

['123 Main Street', '455 Fifth Avenue', '85 Daimler St']

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 #...
Implement a class Address. An address has a house number, a street, an optional apartment number,...
Implement a class Address. An address has a house number, a street, an optional apartment number, a city, a state, and a postal code (all of these are strings). Create the getters and setters. Supply two constructors that accept all the address components except one includes an apartment number and one without (refer to the tester class below to see the proper order). Supply a print method that returns void and prints to the console the address with the street...
: Create a Java program that will accept a regular expression and a filename for a...
: Create a Java program that will accept a regular expression and a filename for a text file. The program will process the file, looking at every line to find matches for the regular expression and display them. Regular Expression Format : The following operators need to be accepted: + - one or more of the following character (no groups) * - zero or more of the following character (no groups) [] – no negation, no character spans – the...
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
create a regular expression in Java that defines the following. A "Stir" is a right brace...
create a regular expression in Java that defines the following. A "Stir" is a right brace '}' followed by zero or more lowercase letters 'a' through 'z' and decimal digits '0' through '9', followed by a left parenthesis '('.
C# Create a console application that prompts the user to enter a regular expression, and then...
C# Create a console application that prompts the user to enter a regular expression, and then prompts the user to enter some input and compare the two for a match until the user presses Esc: The default regular expression checks for at least one digit. Enter a regular expression (or press ENTER to use the default): ^[a- z]+$ Enter some input: apples apples matches ^[a-z]+$? True Press ESC to end or any key to try again. Enter a regular expression...
C# & ASP.NET Create a console application that prompts the user to enter a regular expression,...
C# & ASP.NET Create a console application that prompts the user to enter a regular expression, and then prompts the user to enter some input and compare the two for a match until the user presses Esc: The default regular expression checks for at least one digit. Enter a regular expression (or press ENTER to use the default): ^[a- z]+$ Enter some input: apples apples matches ^[a-z]+$? True Press ESC to end or any key to try again. Enter a...
Using Python, Regular Expressions, .map() and other functions as appropriate to format existing address records and...
Using Python, Regular Expressions, .map() and other functions as appropriate to format existing address records and eliminate records with missing critical fields.Critical fieldsincludeFirstName, Lastname, Zipcode+4, and Phone number for customers. For this exercise, create an array to hold data with these 4 fields containing at least 25records. The Zipcode field should contain either traditional 5-digit Zipcode(e.g. 21801)or Zip+4 format(e.g 21801-1101). The phone numbers should contain 10-digit (e.g. 5555555555)or formatted 10-digit(e.g. 555-555-5555). Some records might be corrupt so the data needs...
Create an ApartmentException class whose constructor receives a string that holds a street address, an apartment...
Create an ApartmentException class whose constructor receives a string that holds a street address, an apartment number, a number of bedrooms, and a rent value for an apartment. Upon construction, throw an ApartmentException if any of the following occur: • The apartment number does not consist of 3 digits • The number of bedrooms is less than 1 or more than 4 • The rent is less than $500.00 or over $2500 Write a driver class that demonstrates creating valid...
Create and test an HTML document for yourself, including your name, address, and electronic mail address....
Create and test an HTML document for yourself, including your name, address, and electronic mail address. If you are a student, you must include your major and your grade level. If you work, you must include your employer, your employer’s address, and your job title. This document must use several headings and <em>, <strong>, <hr />, <p>, and <br /> tags. 2.2 Add pictures of yourself and at least one other image (of your friend, spouse, or pet) 2.3 Add...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT