I am converting a Google Sheets file into a CSV format.
Some cells have an image inserted into them via =IMAGE("https://placekitten.com/200/300")
I need to be able to extract in plain text https://placekitten.com/200/300
Is this possible? I've tried SUBSTITUTE but of course that doesn't work.
Thanks to whoever can solve this!
try:
=REGEXEXTRACT(FORMULATEXT(A2); """(.*)""")
I thought that explaining #player0’s answer would be nice, especially for future people.
His answer can be split in 2 parts:
Using FORMULATEXT to get the formula
Using a regular expression to extract the URL from it
The first part is FORMULATEXT. It is pretty self explanatory: it takes a cell and returns the formula as string.
The second part is using a regular expression (see wikipedia article and documentation on the exact syntax used by Google) to extract the URL. In this case #player0 relies on the fact that the URL is the only quoted text of that formula. So using the regex "(.+)" will match the quoted part inside the quotes of the formula, and thus only the URL. When using literal strings in a formula, you need to surround them with quotes (eg hello as "hello"). Double quotes need to be doubled (eg aaa"aaa is written as "aaa""aaa"). So "(.+)" becomes """(.+)""".
References
FORMULATEXT (Docs Editors Help)
REGEXEXTRACT (Docs Editors Help)
Regular expression (Wikipedia)
RE2 syntax (Google’s RE2 repository on GitHub)
Related
I've been searching for a formula on Google Sheets that removes everything from a url, up to the first /. For example:
www.example.com/example/
www.example.com/example/example1
www.example.com/example/example1/example2
to:
/example/
/example/example1/
/example/example1/example2
Any help would be greatly appreciated!
Say your URL is in A1. Then
=regexreplace(A1,"[\w.-]*\.com/","")
works as long as the site portion of your URLs always end with .com.
When that is not true, it's a bit more cumbersome:
=substitute(A20,regexextract(A20,"[\w-.]*/"),"")
Quickly on why they work: [\w.-] means any character from A-Z, a-z, 0-9, _, ., -. * means any number of the preceding. regexreplace() replaces all matching patterns. And that's why without specifically .com, regexreplace() doesn't work for your problem. regexextract() extracts the part of URL that you don't want. So we can use substitute() to get rid of it.
If you are new to regular expression, I think this example is simple enough to get a little bit into it. For more complex scenarios, the use of regular expression will save us tons of work.
In your current problem, since you only need to recognize the first occurrence of / without more complex patterns, we can just search for that with find() and thus
=right(A1,len(A1)-find("/",A1))
also works.
Try this
on column A is your input
paste this in column B =IF(A2="",,RIGHT(REGEXEXTRACT(A2,".com\/.+"),LEN(REGEXEXTRACT(A2,".com\/.+"))-4))
you can drag it down without any problem
Hope it answered your question.
I've found there are 2 regex languages in Google Sheets.
First is used in formulas:
REGEXEXTRACT
REGEXREPLACE
REGEXMATCH
Second is used in QUERY
=QUERY({A4:C};"where Col1 matches 'West|East'")
The syntax for regular REGEX-like formulas is described here:
https://github.com/google/re2/blob/main/doc/syntax.txt
I've done quick research for QUERY regex and made this table:
You may see I've found some interesting differences about QUERY regex:
always matches the whole string, and you need to add .* if needed.
surprisingly supports "Lookahead" (?=group)
cannot use flags (?i), (?m)
by default fetches single lines of text only, but supports newline \n
Do you have your own research, or found some official docs?
Sheets specific functions
As you stated, there are three different Sheets functions that make use of this "matching" functionality: REGEXEXTRACT, REGEXREPLACE and REGEXMATCH. They accomplish different goals yet their syntactical implementation is pretty similar. You can find their documentation here:
REGEXEXTRACT. Documentation.
REGEXREPLACE. Documentation.
REGEXMATCH. Documentation.
And, as you stated, the full documentation on the syntax they use can be found here: https://github.com/google/re2/blob/main/doc/syntax.txt
Query function
The QUERY function (you can read its documentation here) uses the well-known SQL syntax, (notwithstanding the few exceptions listed in the documentation where they differ). In the official documentation there is a summary about basic SQL syntax (here), but of course for more detail you would need to go to the SQL documentation.
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"))
i am new in using notion as a notebook.Before this,i use oneNote instead,because i found that notion is more convinient in same ways.But one thing making me annoyed is that i can't add subscript(or superscript) in notion text block。Are there any fellows can handle this?
as shown:
text with subscript i need
when i edit in notion block i get like this
For subscript:
/math
Then C_1 renders C1
For superscript:
/math
Then C^2 renders C2
In the latest version as of writing, you could use:
$$c^2$$ - for superscript
$$c_2$$ - for subscript
If you write any mathematical equation between $$ $$, it will render beautifully on notion.
For more than 1 character superscript
/math
P^{xyz}
Result: Pxyz
For more than 1 character subscript
/math
P_{xyz}
Result: Pxyz
In fact, this works for 1 or many characters as subscript or superscript.
Even I just started using notion and faced the same problem. The solution I found was to keep a tab of laTex containing the syntax for all the required math formulae open. It is only temporary as you will get used to them pretty quickly.
You can use tex to write things is superscript or subscript or basically any type of formulae , but its still in tex.
I did and worked on my Notion
Step 1: Choose what to add subscript(or superscript) in notion block (Example a^n)
Step 2: Choose symbol sqrt(x)
Step 3: Press "Done"
In Notion, there are two ways to add math formulas: inline equations and block equations. Both use KaTeX formatting to show the formulas. KaTeX is a TeX display formulas method based on JavaScrpt language. When you place a block or inline equation, for your example, you have to do something like that in the code:
w_{1}=0 ~,~ w_{2}=1
Note that spaces are not rendered, you gotta use ~ separate things, and the { } on these subscripts are optional because when not placed, the "" will take just the first next character. To do superscript, change the "" to "^". You can combine both in the same main variable, like w_2^2=1.
In the following links, you can see a Notion's guide about how to use it, the supported features KaTeX allows you to do, and a link to easy creating formulas.
Notion:
https://www.notion.so/help/math-equations
KaTeX Supported Functions:
https://katex.org/docs/supported.html or
https://katex.org/docs/support_table.html
Easy web TeX editor:
https://atomurl.net/math/
Take time to try and explore writing by typping. Then, when you get used to it, it flows easily like writing regular text.
For anyone stumbling upon this question who does not want to write math equations but simply wants to add a couple of superscript or exponent elements to a Notion page, for instance to write footnotes: there seems to be no way to add "simple" superscript (inline and with the same font), but you can use superscript unicode characters, for instance with a tool such as this one.
It is not perfect as many characters are not available, but will cover many¹ common² uses³ of superscriptᶜᶦᵗᵃᵗᶦᵒⁿ ⁿᵉᵉᵈᵉᵈ.
Can custom formula based conditional formatting use NamedRanges ?
I'm experiencing that when named range is used, I cannot save the conditional formatting because formula is invalid, but when the NamedRange is replaced by a string it works. The docs do not allude to details, AFAIK.
ISNUMBER(INDIRECT("ArrivalTimes!$A$4:$S$653")) // OK
ISNUMBER(INDIRECT(RNG_ArrTimes)) // now allowed to save
Is this expected behaviour? Any docs available on this?
EDIT; based on answer for reader convenience.
AS suggested by #pnuts, it works when the range name is within double quotation marks.
However, while INDIRECT expects a string, in Sheets INDIRECT accepts NamedRanges as is without quotation marks. But, for conditional formatting, the named range must be within quotation marks. I have not found any docs that document or explain this behavior.
Can custom formula based conditional formatting use NamedRanges ?
Indeed they can.
The rest of your Q is unclear to me but perhaps it is just that you are missing double quotes around the Name of your range (and = at the beginning?).