exec() method of RegExp object returns only first match

Hi,

I'm having trouble with the RegExp object's exec() method, which according to the docs shoudl return an array of all matches.  For me, it only returns the first match.

I am trying to use it to identify the cameras in a .duf file.  There are two instances of the string "camera" in the file - one as such, and one as "current_camera", but exec() only returns the first when using the pattern "camera".

var filedir = new DzDir("C:/Users/blah/Documents/DAZ 3D/Studio/My Library/Scenes");var filename = new DzGZFile(filedir.path() + "/TestScene01.duf");if ( ! filename.exists() ) {	print("File not found");}if ( filename.open( DzFile.ReadOnly ) ) {	print(String("File opened, size %1").arg(filename.size()));	var lines = filename.read();	print("Length " + lines.length);	var obj = JSON.parse(lines);	var dufstr = JSON.stringify(obj);		for (var ok = 0; ok < Object.keys(obj).length; ok++ ) {		print(Object.keys(obj)[ok]);	}	//var rg = new RegExp("camera","gm");	//var rg = /camera/gm;	var rg = new RegExp( /camera/gm );	var aCams = rg.exec(dufstr);	print("aCams length = " + aCams.length);	print("idx = " + rg.search(dufstr));	for (var x = 0; x < aCams.length; x++) {		print("x: " + x + " - " + aCams[x]);	}}

No matter how I define the regex, and with or without the g and m pattern flags, the results I get are these:

File opened, size 17297Length 195878file_versionasset_infogeometry_librarynode_libraryuv_set_libraryimage_librarymaterial_librarysceneDufstuff length = undefinedaCams length = 1idx = 11858x: 0 - cameraResult: Script executed in 0 secs 22 msecs.

As can be seen, only the first occurence of "camera" is returned, which seems to be incorrect.

Any help/suggestions/corrections appreciated.

Comments

Sign In or Register to comment.