Check string formating

Question:

I need to check the first value on a csv file. It need to match an specific string. "ddd.ddddd" all numbers. All CSV values start and end with ""

Sample string from CSV

"123.12345"

The code so far is

import re
import csv

strformat = re.compile('"d{3}.d{5}"')

with open(final_file, newline='') as fin:
    for f in csv.reader(fin[0]):
        if strformat is not None:
            print ("Match")
        else:
            print ("No Match")
Asked By: Ae3erdion

||

Answers:

You need to reverse your code like this,

# The expression is changed
strformat = re.compile(r'd{3}.d{5}') 

with open(final_file, newline='') as fin:
    for row in csv.reader(fin):
        # You have to check match like this
        if strformat.match(row[0]):
            print ("Match")
        else:
            print ("No Match")
Answered By: Rahul K P
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.