Actually, I would think that regex would be the only way to get a search and replace to do what needs done.
I generated some marlin-compatible gcode with the piclaser software to see what it looks like. Here’s a sample:
M106 M03 G1 X0 Y0 M105 S236 G1 X0 Y0 M105 S236 G1 X0 Y0 M105 S236 G1 X0 Y0 M105 S235 G1 X0 Y0 M105 S235 G1 X0 Y0 M105 S235 G1 X0 Y0 M105 S236 G1 X0 Y0
Note that each line with coordinates needs to have a G1 code. The GRBL code apparently doesn’t need it, since it looks like this:
G1 M3 X0Y102.42S143 X0.18S134 X0.36S135 X0.54S133 X0.72S118 X0.9S111 X1.08S97 X1.26S92
Just thought I’d point that out, since you’re looking at modifying the function to create gcode we can use with our marlin-based machines.