If I want to use JavaScript RegExp to match an expression string, how can I do it effectively?
For example:
'1**2*3+4'
->
['1', '**', '2', '*', '3', '+', '4']
,
rather than ['1', '*', '*', '2', '*', '3', '+', '4']
Is there a way to achieve this using the following RegExp pattern?
'1**2*3+4'.match(/[*\/+-]|\d+/g)
Additionally, is it possible to group (\*\*)
together with +-*/
in brackets without making them stand out individually like:
/\*\*|[*\/+-]|\d+/g