Finding characters in the middle of a string that includes " - google-sheets

I have the following extract of code. My aim is to extract the value 7.4e-07 after the symbol DAN. My usual go-to formula (using MID & FIND formula's) for this can't work because DAN is surrounded by ", and therefore confuses the formula.
{"data":{"log":{"address":[{"balances":[{"currency":{"address":"example1","symbol":"ROB"},"value":0.0},{"currency":{"address":"example2","symbol":"DAN"},"value":7.4e-07},{"currency":{"address":"example3","symbol":"COLIN"},"value":0.0},{"currency":{"address":"example4","symbol":"BOB"},"value":0.0},{"currency":{"address":"example5","symbol":"PAUL"},"value":13426.64}}}
I will always need to find the number shown in the 'value' after DAN. However, all other data surrounding will change so cannot be used in the search formula.
Any help would be appreciated.

The extract the digit you want, it can be achieved by using regex, split, index, here is the formula, accept if help :)
=index(split(REGEXEXTRACT(A1,"\""DAN\""},\""value\"":[\d.a-zA-Z-]+"),":"),0,2)
This is the regex I used to extract the value including the beginning text
"DAN"},"value":[\d.a-zA-Z-]+
This is outcome from the regex,

You could try an arrayformula to work down the sheet, extracting all values after 'DAN':
=arrayformula(regexreplace(A1:A,".*(DAN...........)([\w\.\-]*)(\}.*)","$2"))

Related

Getting what is in between brackets from a value

I have the following value in a cell:
May 04, 2022 (50bp)
I need only what is in between ( and ). I was thinking of using =RIGHT() but I never know how much is inm between the two brackets (so the number of characters I have to give as a parameter to RIGHT(), will differ.
What is the correct way of handling this in Google Sheets?
Use REGEXEXTRACT() function.
=REGEXEXTRACT(A1,"\((.*)\)")
To extract the text between any characters, use a formula with the MID and FIND functions despite how much is in between the two brackets.
=MID(A1,FIND("(",A1)+1,FIND(")",A1)-FIND("(",A1)-1)
more information here

Convert text to number in Google Sheets

I'm reading currency values from a website and I'd like to do some calculations with these numbers. They come in this format:
$7,821.24
Here's an example file:
https://docs.google.com/spreadsheets/d/1vHEH_m16KXcDh7hY_BVG9lur1huFjWOnx5bWtgrdGdA/edit?usp=sharing
Now for some reason neither VALUE() and TO_PURE_NUMBER work for me (Can't parse to numberic value, telling me it's a text value).
My guess is that the comma and the $-sign confuse the formula, is there anything I can do to format this correctly? The dollar sign always appears in the values but the comma only appears separating thousands of values.
I just started using Sheets for this so I absolutely have no clue. Would really appreciate if someone could help me out.
Thanks for your time!
Issue:
It's a locale problem. The value coming from IMPORTXML is formatted as in United States locale, so your spreadsheet (which uses a different format) cannot convert it.
Solution #1. Changing locale:
If the spreadsheet locale is changed to United States or others with the same format (via selecting File > Spreadsheet settings and setting the mentioned locale), the retrieved value will be a number, and you can work with it without using any other formula.
Solution #2. Formula:
If changing the locale is not an option, one possible way to convert the value to a valid number in your locale is the following formula:
=SUBSTITUTE(SUBSTITUTE(RIGHT(A2;LEN(A2)-1);",";"");".";",")
Changing locale didn't work in my case. But I was able to split the number which google sheet isn't detecting as a real number. So split it with "," and "." and any currency sign you may have, and then combine individual values for desired output

Google Sheets Parse Mathematical Expressions in Text Format

Is there a way to take a text in a cell that says 5*5 and to parse to make the result 25... using QUERY function or any of the other built-in functions...?
it would be like this:
=QUERY(SPLIT(B19, "*"), "select Col1*Col2 label Col1*Col2''")
No. But if you have all such Mathematical expressions in a defined range(say,A5:A7), then you can use Find and Replace
FIND:
^
REPLACE:
=
Range:
Sheet1!A5:A7
Checkmark "Search using regular expressions". Click Replace all. Otherwise you'll need scripts.
IF you are just looking to parse simple mathematical expressions (+,-,x,/), then it can be done, but not in a single formula.
First, you can split the text based on your math operator, which will provide the numbers. Then you can use regexextract to output the math operator, then use a nested if to perform the needed math operation on the numbers, based upon that operator. You can hide the intermediate columns to put the answer next to the original.
Note that if you need to do more complex operations or operations on more than two numbers, this will not work.

Extracting a numeric string from URL

I was trying to extract this numeric string: 232546102069 from the given link:
http://www.abc.in/itm/fawf-asdfsafjsaf-jasfh-lbadfugo-hasdhf-asdijfh-xpq/232546102069?hash=item3624d3eb35:g:BU4AAOSwm3pZ-cQV
using regex in Sheets.
Can anyone help me with the logic and its explanation?
Any help would be greatly appreciated.
Try matching the following pattern:
http:\/\/www.*\/(\d+)\?
The number you want to capture will be available in the first capture group. I make the assumption here that the 12 digit number you want to capture will always occur immediately before the start of the query string.
Demo

seaching 2D ArrayLib does not work for some cases

I have 2D array in which the second column has domain names of some emails, let us call the array myData[][]. I decided to use ArrayLib in order to search the second column for a specific domain.
ArrayLib.indexOf(myData, 1, domain)
Here is where I found an issue. In myData array, one of the domains look like this "ewmining.com" (pay attention to the w).
While searching for "e.mining.com" (notice the first dot), the indexOf() function actully gave me the row containing "ewmining.com".
This is what is in the array "ewmining.com"
This is what is in the serach string "e.mining.com"
It seams that ArrayLib treats the dot to mean any character. Is this supposed to be the correct behavior? Is there a way to stop this behavior and search for exact match.
I really need help on this issue.
Thanks in advance for your help.
The dot usually represents "any character" in regular expressions. I am not familiar with ArrayLib, but maybe you should look for a way to turn off regular expressions when searching. Otherwise you might have to escape the dot, for example search for e[.]mining[.]com

Resources