I am trying to extract all cell/range addresses appear with in a formula in a Google Sheets cell.
Formulas by nature might be very complicated. I tried many patterns, that works in web testers, but not on google sheets re2.
The following example shows two issues. Maybe I misreading the matching results, but as I understand the are 4 Matches.
Formula (ignore the logic):
=A$13:B4+$BC$12+$DE2+F2:G2
Regex:
((\$?[A-Z]+\$?\d+)(:(\$?[A-Z]+\$?\d+))?)
Expected result:
[A$13:B4,$BC$12,$DE2,F2:G2]
Here (if I am not misreading the results) it looks OK. I am not sure if the group matching displayed are also considered as matches as it is stated "4 matches, 287 steps"
However in google sheets returns all Match 1 results
[A$13:B4,A$13,:B4,B4]
The other matches are ignored So I guess the question is how to convert the regex to re2 syntax?
Update: Following player0 comments, maybe I was not clear. This is only a simple example, to isolate other issues I have. This one is just a string containing addresses in few relative and absolute formats. However, I am looking for a wider general solution that will fit any possible formulas that might contain formulas and references to other sheets. For example:
=(STDEVA(Sheet1!B2:B5)+sum($A$1:$A$2))*B2
Expected results here is Sheet1!B2:B5,$A$1:$A$2,B2
This formula contains two formulas and reference to another sheet. Still ignoring here from Named Ranges and other formula possible references that I am currently can not think of. Also, the square brackets [] are irrelevant, it was just way to display the results, and actually is copied from Logs as it is all done within a script.
\$?[A-Z]+\$?\d+(?::(?:\$?[A-Z]+\$?\d+))?
regex101.com/r/A5yKb5/1 – The fourth birdA$13:B4
– OJNSim