STL loader has issue in regex

The STL loader uses the following regular expression to identify solids:

/solid (\S*)([\S\s])endsolid[ ](\S*)/g

This works in the case of a single solid. However, if fails with a valid STL file when multiple solids are present. For example:

solid name1

endsolid name1
solid name2

endsolid name2

will lead to an error in importMesh, because with this example the code will compare:

var meshName = matches[1]; // matches to name1 in the example
var meshNameFromEnd = matches[3]; // matches to name2 in the example

Also, it is not clear what the while loop does, since with this regex, the match can only be one or none at all.

The correct regex should be:

/solid (\S*)([\S\s]?)endsolid[ ](\S*)/g


Thanks a lot for the great analysis !!! could you share such file so I could try out the fix ???

Thank you for the prompt response!

Please, see the link (I am new to the forum, so I cannot attach files):!AoX9NwyBCY-bgecWhDZRSqKmmqlH3g?e=svBpU7

To give credit: I have concatenated the three ASCII STLs in the three.js examples to make this file. :sweat_smile:

I also tested the regex at using:

solid name1

endsolid name1
solid name2

endsolid name2

1 Like

Perfect will be fixed in the next nightly in about 30 min :slight_smile:


Great! Thank you :slight_smile: