Javascript - regex only catches the first 3 matches -
first, in advance can provide.
my regex capturing first 3 instances of string i'm trying extract. ideas?
my code:
var objargs = wscript.arguments; var objfilesys = new activexobject("scripting.filesystemobject"); var objfolder = objfilesys.getfolder(objargs.item(0)); var objtsetnum = new regexp("^st.((\\d+)+)", "gm"); var objfile = null; var srcfile = null; (var objfileenum = new enumerator(objfolder.files); !objfileenum.atend(); objfileenum.movenext()) { objfile = objfilesys.opentextfile(objfileenum.item(), 1, false, 0); srcfile = objfile.readall(); objfile.close(); // check different values in tset entries // build array hold tset values found var arrtset; while ((arrtset = objtsetnum.exec(srcfile)) !== null) { // arrtset = objtsetnum.exec(srcfile); wscript.echo("arrtset is: " + arrtset); wscript.echo("length of arrtset is: " + arrtset.length) //var alltsetsame = true; }
and sample text file has 5 instances of line beginning "st*" - shouldn't 5 placed array?:
isa*00* *00* *01*041199639 *08*9272590000 *150704*1131*u*00401*000001324*0*p*: st*865*0001 st*865*0001 st*865*0001 st*865*0001 st*865*0001 iea*5*000001324
any advice? hunch telling me exec() function changing something, can't find details might changing.
appreciate help!
edit: of course, once posted it, found answer. exec() stateful, needed push each result returned array, similar to:
var arrtset = []; var match; while (match = objtsetnum.exec(srcfile)) { arrtset.push(+match[1]); }
which found here (giving credit): why javascript's regex.exec() not return same value?
what think problem might regexp.exec doesn't return array of possible results, returns first result matches in result. if through array back, matches be:
st*865
865
865
exec continue return next match each time call it
Comments
Post a Comment