I would like to perform checking on the following:
VALID LINES;
/**/ some code
*/ some code /** dsfsdkf sd**/
NOT VALID LINES;
/**/ //some code
*/ /***/ //somecode
So basically if there is a line of code outside a comment it is valid, otherwise not.
What would be the best way to tackle this kind of validation?
Note:
For */ I assume that the /* has been opened some lines before.
This should be quite fast I believe.
If you read up a bit on the internals of reg-exps you’ll realize that regular expressions are quite efficient once the underlying automaton has been compiled and minimized (at least for simple regular expressions like the one above). No matter how you implement your algorithm, it would still need to do roughly the same work that the reg-exp engine does in this scenario anyway.
(If you look at the
String.splitmethod, you’ll note that the internal regular expression is compiled into aPatternonce and for all.)