SlideShare ist ein Scribd-Unternehmen logo
1 von 1
I need this to be written in python using regex: 1) identify all valid prices that appear in the file A
valid price may be represented in the following forms $x, where x is a string of one or more
digits with the restriction that the 1 st digit is NOT zero $x.bc, where x is string of one or more
digits, where 1 st digit can be zero ONLY if x is a single character b & c are single digits in
either case, if x is longer than 3 digits, commas are used to separate subsequences of 3 digits
Invalid formats include $y, where y is a string of one or more digits but the 1 st digit is zero $x.b,
where b is a string of 1 or (3 or more) digits $y.b, where y is as described above, and b is a string
of 1 or (3 or more) digits
Solution
import re
fileName = raw_input("Enter file name")
input = open(fileName, 'rb')
for line in file:
matchObj = re.match(r'^[1-9]d*(.d+)?$', line)
if matchObj:
print matchObj

Weitere ähnliche Inhalte

Mehr von patriciab30

ID-D Samei- -14- Which ofthe following should sever be evaporwedon-hpl.docx
ID-D Samei- -14- Which ofthe following should sever be evaporwedon-hpl.docxID-D Samei- -14- Which ofthe following should sever be evaporwedon-hpl.docx
ID-D Samei- -14- Which ofthe following should sever be evaporwedon-hpl.docxpatriciab30
 
I- Physical Properties- Color-- Clear Odor- Nail polish Yemover (corre.docx
I- Physical Properties- Color-- Clear Odor- Nail polish Yemover (corre.docxI- Physical Properties- Color-- Clear Odor- Nail polish Yemover (corre.docx
I- Physical Properties- Color-- Clear Odor- Nail polish Yemover (corre.docxpatriciab30
 
I- H low do you know when to name something as an ionic compound- 2- H.docx
I- H low do you know when to name something as an ionic compound- 2- H.docxI- H low do you know when to name something as an ionic compound- 2- H.docx
I- H low do you know when to name something as an ionic compound- 2- H.docxpatriciab30
 
I- Which type of star oscillates in brightness in a pattern in such a.docx
I- Which type of star oscillates in brightness in a pattern in such a.docxI- Which type of star oscillates in brightness in a pattern in such a.docx
I- Which type of star oscillates in brightness in a pattern in such a.docxpatriciab30
 
I- Describe the different bonds that exist between the different macro.docx
I- Describe the different bonds that exist between the different macro.docxI- Describe the different bonds that exist between the different macro.docx
I- Describe the different bonds that exist between the different macro.docxpatriciab30
 
I- Anole Company 25 POINTS Anole Company was incorporated as a new bus.docx
I- Anole Company 25 POINTS Anole Company was incorporated as a new bus.docxI- Anole Company 25 POINTS Anole Company was incorporated as a new bus.docx
I- Anole Company 25 POINTS Anole Company was incorporated as a new bus.docxpatriciab30
 
I) What are secondary bonding interactions (also called charge transfe.docx
I) What are secondary bonding interactions (also called charge transfe.docxI) What are secondary bonding interactions (also called charge transfe.docx
I) What are secondary bonding interactions (also called charge transfe.docxpatriciab30
 
I need to write a soil chemistry paper using scientific articles and j.docx
I need to write a soil chemistry paper using scientific articles and j.docxI need to write a soil chemistry paper using scientific articles and j.docx
I need to write a soil chemistry paper using scientific articles and j.docxpatriciab30
 
I need help with CH4- What is its intermolecular force- Question 4 of.docx
I need help with CH4- What is its intermolecular force- Question 4 of.docxI need help with CH4- What is its intermolecular force- Question 4 of.docx
I need help with CH4- What is its intermolecular force- Question 4 of.docxpatriciab30
 
I need help writing this program in MIPS MARS assembly language 2- Mak.docx
I need help writing this program in MIPS MARS assembly language 2- Mak.docxI need help writing this program in MIPS MARS assembly language 2- Mak.docx
I need help writing this program in MIPS MARS assembly language 2- Mak.docxpatriciab30
 
I need help writing a python 3 function- I need to write a function th.docx
I need help writing a python 3 function- I need to write a function th.docxI need help writing a python 3 function- I need to write a function th.docx
I need help writing a python 3 function- I need to write a function th.docxpatriciab30
 
I need help with my geotechnical engineering HW-- Can a soil have a lo.docx
I need help with my geotechnical engineering HW-- Can a soil have a lo.docxI need help with my geotechnical engineering HW-- Can a soil have a lo.docx
I need help with my geotechnical engineering HW-- Can a soil have a lo.docxpatriciab30
 
I need help m5 In the modern Respond to the following questions with s.docx
I need help m5 In the modern Respond to the following questions with s.docxI need help m5 In the modern Respond to the following questions with s.docx
I need help m5 In the modern Respond to the following questions with s.docxpatriciab30
 
I need help describing the two kinds of people who are responsible for.docx
I need help describing the two kinds of people who are responsible for.docxI need help describing the two kinds of people who are responsible for.docx
I need help describing the two kinds of people who are responsible for.docxpatriciab30
 
12- Your friend has high protein and sugar in her urine- She repeats t.docx
12- Your friend has high protein and sugar in her urine- She repeats t.docx12- Your friend has high protein and sugar in her urine- She repeats t.docx
12- Your friend has high protein and sugar in her urine- She repeats t.docxpatriciab30
 
12- Under which of the following circumstances is the principal-agent.docx
12- Under which of the following circumstances is the principal-agent.docx12- Under which of the following circumstances is the principal-agent.docx
12- Under which of the following circumstances is the principal-agent.docxpatriciab30
 
12- An Asteroid passes by Earth every 17 years- The asteroid orbits th.docx
12- An Asteroid passes by Earth every 17 years- The asteroid orbits th.docx12- An Asteroid passes by Earth every 17 years- The asteroid orbits th.docx
12- An Asteroid passes by Earth every 17 years- The asteroid orbits th.docxpatriciab30
 
11- What are the components of the user interface-SolutionNow a days t.docx
11- What are the components of the user interface-SolutionNow a days t.docx11- What are the components of the user interface-SolutionNow a days t.docx
11- What are the components of the user interface-SolutionNow a days t.docxpatriciab30
 
11- The employer payroll tax expense on employee wages that is paid fo.docx
11- The employer payroll tax expense on employee wages that is paid fo.docx11- The employer payroll tax expense on employee wages that is paid fo.docx
11- The employer payroll tax expense on employee wages that is paid fo.docxpatriciab30
 
110) When you create a form from two tables that have a one-to-many re.docx
110) When you create a form from two tables that have a one-to-many re.docx110) When you create a form from two tables that have a one-to-many re.docx
110) When you create a form from two tables that have a one-to-many re.docxpatriciab30
 

Mehr von patriciab30 (20)

ID-D Samei- -14- Which ofthe following should sever be evaporwedon-hpl.docx
ID-D Samei- -14- Which ofthe following should sever be evaporwedon-hpl.docxID-D Samei- -14- Which ofthe following should sever be evaporwedon-hpl.docx
ID-D Samei- -14- Which ofthe following should sever be evaporwedon-hpl.docx
 
I- Physical Properties- Color-- Clear Odor- Nail polish Yemover (corre.docx
I- Physical Properties- Color-- Clear Odor- Nail polish Yemover (corre.docxI- Physical Properties- Color-- Clear Odor- Nail polish Yemover (corre.docx
I- Physical Properties- Color-- Clear Odor- Nail polish Yemover (corre.docx
 
I- H low do you know when to name something as an ionic compound- 2- H.docx
I- H low do you know when to name something as an ionic compound- 2- H.docxI- H low do you know when to name something as an ionic compound- 2- H.docx
I- H low do you know when to name something as an ionic compound- 2- H.docx
 
I- Which type of star oscillates in brightness in a pattern in such a.docx
I- Which type of star oscillates in brightness in a pattern in such a.docxI- Which type of star oscillates in brightness in a pattern in such a.docx
I- Which type of star oscillates in brightness in a pattern in such a.docx
 
I- Describe the different bonds that exist between the different macro.docx
I- Describe the different bonds that exist between the different macro.docxI- Describe the different bonds that exist between the different macro.docx
I- Describe the different bonds that exist between the different macro.docx
 
I- Anole Company 25 POINTS Anole Company was incorporated as a new bus.docx
I- Anole Company 25 POINTS Anole Company was incorporated as a new bus.docxI- Anole Company 25 POINTS Anole Company was incorporated as a new bus.docx
I- Anole Company 25 POINTS Anole Company was incorporated as a new bus.docx
 
I) What are secondary bonding interactions (also called charge transfe.docx
I) What are secondary bonding interactions (also called charge transfe.docxI) What are secondary bonding interactions (also called charge transfe.docx
I) What are secondary bonding interactions (also called charge transfe.docx
 
I need to write a soil chemistry paper using scientific articles and j.docx
I need to write a soil chemistry paper using scientific articles and j.docxI need to write a soil chemistry paper using scientific articles and j.docx
I need to write a soil chemistry paper using scientific articles and j.docx
 
I need help with CH4- What is its intermolecular force- Question 4 of.docx
I need help with CH4- What is its intermolecular force- Question 4 of.docxI need help with CH4- What is its intermolecular force- Question 4 of.docx
I need help with CH4- What is its intermolecular force- Question 4 of.docx
 
I need help writing this program in MIPS MARS assembly language 2- Mak.docx
I need help writing this program in MIPS MARS assembly language 2- Mak.docxI need help writing this program in MIPS MARS assembly language 2- Mak.docx
I need help writing this program in MIPS MARS assembly language 2- Mak.docx
 
I need help writing a python 3 function- I need to write a function th.docx
I need help writing a python 3 function- I need to write a function th.docxI need help writing a python 3 function- I need to write a function th.docx
I need help writing a python 3 function- I need to write a function th.docx
 
I need help with my geotechnical engineering HW-- Can a soil have a lo.docx
I need help with my geotechnical engineering HW-- Can a soil have a lo.docxI need help with my geotechnical engineering HW-- Can a soil have a lo.docx
I need help with my geotechnical engineering HW-- Can a soil have a lo.docx
 
I need help m5 In the modern Respond to the following questions with s.docx
I need help m5 In the modern Respond to the following questions with s.docxI need help m5 In the modern Respond to the following questions with s.docx
I need help m5 In the modern Respond to the following questions with s.docx
 
I need help describing the two kinds of people who are responsible for.docx
I need help describing the two kinds of people who are responsible for.docxI need help describing the two kinds of people who are responsible for.docx
I need help describing the two kinds of people who are responsible for.docx
 
12- Your friend has high protein and sugar in her urine- She repeats t.docx
12- Your friend has high protein and sugar in her urine- She repeats t.docx12- Your friend has high protein and sugar in her urine- She repeats t.docx
12- Your friend has high protein and sugar in her urine- She repeats t.docx
 
12- Under which of the following circumstances is the principal-agent.docx
12- Under which of the following circumstances is the principal-agent.docx12- Under which of the following circumstances is the principal-agent.docx
12- Under which of the following circumstances is the principal-agent.docx
 
12- An Asteroid passes by Earth every 17 years- The asteroid orbits th.docx
12- An Asteroid passes by Earth every 17 years- The asteroid orbits th.docx12- An Asteroid passes by Earth every 17 years- The asteroid orbits th.docx
12- An Asteroid passes by Earth every 17 years- The asteroid orbits th.docx
 
11- What are the components of the user interface-SolutionNow a days t.docx
11- What are the components of the user interface-SolutionNow a days t.docx11- What are the components of the user interface-SolutionNow a days t.docx
11- What are the components of the user interface-SolutionNow a days t.docx
 
11- The employer payroll tax expense on employee wages that is paid fo.docx
11- The employer payroll tax expense on employee wages that is paid fo.docx11- The employer payroll tax expense on employee wages that is paid fo.docx
11- The employer payroll tax expense on employee wages that is paid fo.docx
 
110) When you create a form from two tables that have a one-to-many re.docx
110) When you create a form from two tables that have a one-to-many re.docx110) When you create a form from two tables that have a one-to-many re.docx
110) When you create a form from two tables that have a one-to-many re.docx
 

Kürzlich hochgeladen

General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIFood Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIShubhangi Sonawane
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfChris Hunter
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 

Kürzlich hochgeladen (20)

General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIFood Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 

I need this to be written in python using regex- 1) identify all valid (1).docx

  • 1. I need this to be written in python using regex: 1) identify all valid prices that appear in the file A valid price may be represented in the following forms $x, where x is a string of one or more digits with the restriction that the 1 st digit is NOT zero $x.bc, where x is string of one or more digits, where 1 st digit can be zero ONLY if x is a single character b & c are single digits in either case, if x is longer than 3 digits, commas are used to separate subsequences of 3 digits Invalid formats include $y, where y is a string of one or more digits but the 1 st digit is zero $x.b, where b is a string of 1 or (3 or more) digits $y.b, where y is as described above, and b is a string of 1 or (3 or more) digits Solution import re fileName = raw_input("Enter file name") input = open(fileName, 'rb') for line in file: matchObj = re.match(r'^[1-9]d*(.d+)?$', line) if matchObj: print matchObj