Using ^ to match beginning of line in Python regex -


i'm trying extract publication years isi-style data thomson-reuters web of science. line "publication year" looks (at beginning of line):

py 2015 

for script i'm writing have defined following regex function:

import re f = open('savedrecs.txt') wosrecords = f.read()  def findyears():     result = re.findall(r'py (\d\d\d\d)', wosrecords)     print result  findyears() 

this, however, gives false positive results because pattern may appear elsewhere in data.

so, want match pattern @ beginning of line. use ^ purpose, r'^py (\d\d\d\d)' fails @ matching results. on other hand, using \n seems want, might lead further complications me.

re.findall(r'^py (\d\d\d\d)', wosrecords, flags=re.multiline) 

should work, let me know if doesn't. don't have data.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -