Skip to content
Advertisement

what I cant splir the char of ‘(‘ using this regexp in javascipt

the var codigo have the value *int a,h;float b,c;a=b*(c+h);

my regex is:

JavaScript

and as a output im getting this:

JavaScript

JavaScript

why after the ‘*’ the ‘(‘ isnt splitting right ? when the ‘)’ its doing correctly?

Advertisement

Answer

In Regular Expressions, since . represents any character, it should be enough to split by the following regex:

JavaScript

and then remove the empty string elements, using .filter(Boolean).

Working Example:

JavaScript
Advertisement