I am working with regular expressions in Python. I want to match a few lines from a CSV file inserted into a database that starts and ends with an underscore.
I have used regular expressions in my Python script to do the same but it prints the result as 'none'. Here is my code for the same, kindly tell me what mistake I am making:
reg = re.compile(r'^_.*_$',re.I)
imatch = reg.match(unicode(row[4], "utf8"))
Here r'^_.*_$',re.I is my regular expression to match lines starting and ending with _. unicode(row[4], "utf8") specifies the row from the CSV file inserted into a database.
Any help would be appreciated.
row[4], and what you're trying to match. Do you know that there are cases that begin and end with a_that are not being matched?_._. Is that not what you want to do?