I think I managed to imitate what you do with awk. AWK Guide Link:
http://www.staff.science.uu.nl/~oostr102/docs/nawk/nawk_92.html
This is what my file looks like:
this,is,a,test,line this, ,a,test,line,with,the,second,field,blank this, is,another,test,line,with,a,blank,in,the,second,field,but,the,field,isnt,blank this, ,is,another,line,with,a,blank,second,field
And here is the command I ran:
awk '{regex = "test"; where = match($0, regex); print "REGEX: ",where," on line ",NR}' test
And the conclusion:
REGEX: 11 on line 1 REGEX: 10 on line 2 REGEX: 18 on line 3 REGEX: 0 on line 4
I did it fast and dirty, but I hope this helps you get what you need.