Let's say I have a string Str1 -> "[18.01,19.023],[20.0289,20.9273],[32.474742,284.383732]"
This is like a set of coordinates of type [x,y] and I want to extract all the "x" and "y" and get these in columns in a dataframe.
How can I do this?
I tried stri_locate_all,regexpr and other commands... When I use [(.*)] as the regex to fetch everything within brackets I end up reading everything from first to last bracket as a string instead of all possible occurrences (i.e. 18.01,19.023],[20.0289,20.9273],[32.474742,284.383732)..
.*
is greedy, use.*?
(lazy, non-greedy, reluctant...).paste0('[',Str1,']') |> jsonlite::fromJSON() |> data.frame()