Here's a typical input string (which I read in as a single line):
I want the resulting array to have 4 elements:attr_def_OID OID, varname vartype1, /* Explanation */ varname vartype2, /* Explanation, details */ varname vartype3, /* Explanation, details, details */ varname vartype4 /* Explanation */
True, the comments don't get grouped with their intended lines, but that's not a problem for my application. I'm just doing some more text transformations, then joining them all back together. The important thing is that the comments come along for the ride.1: varname vartype1 2: /* Explanation */ varname vartype2 3: /* Explanation, details */ varname vartype3 4: /* Explanation, details, details */ varname vartype4 /* Explanation */
This is what I'm using now to do the split, and it's working for the cases I've tried it with so far:
@elements = split(/,(?!(?:[^\/]|\/(?!\*))+\*\/)/, $str);
---
A fair fight is a sign of poor planning.
In reply to Re^2: Splitting outside comments
by Sprad
in thread Splitting outside comments
by Sprad
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |