I am trying to tokenize a jsonpath string. For example, given a string like the following:
$.sensor.subsensor[0].foo[1][2].temp
I want ["$", "sensor", "subsensor", "0", "foo", "1", "2", "temp"]
I am terrible with regexs but I managed to come up with the following which according to regexr matches "." and "[" and "]". Assume the jsonpath string does not contain slices, wildcards, unions nor recursive descent.
[\.\[\]]
I am planning to match all "." and "[" and "]" chars and replace them with ";". Then i will split on ";".
The problem with the above regex is that I will get in certain instances ";;".
$;sensor;subsensor;0;;foo;1;;2;;temp
Is there a way I can in a single regex replace ".", "[", "]" as well as ".[" and "]." or "][" with ";"? Do I need to check for these groups explicitly or do I need to run the sequence through 2 regexs?