Regex in google sheets - Extract parts of URL between slashes - regex

I have difficulties with extracting parts of URL.
What I need is to know what category the product is(jeans, socks, tshirts), and a subcategory what color the product is(blue, black, white)
https://www.examplewebsite.com/shop/jeans/blue/123456
https://www.examplewebsite.com/shop/socks/black/234567
https://www.examplewebsite.com/shop/tshirst/white/4321
What is the best way to extract this in google sheets?

Please try:
=index(split(A1,"/"),,4)
and
=index(split(A1,"/"),,5)
copied down to suit.

={"PRODUCT", "CATEGORY";
INDEX(SPLIT(A2:A, "/"), , 4),
INDEX(SPLIT(A2:A, "/"), , 5)}

Related

SubString match in Google Sheets using Regex and Query

This is the data in google sheets
Account Numkber Names
7728550,543216 Govt Req
772855,65432 Vodafone
I am trying to do a lookup of the account numbers with the formula
=QUERY(Sheet1!B$3:C$4,"Select C where B matches '^.*(" & B2 & ").*$' limit 1")
772855 - Govt req
How do I solve this ? There is a large chunk of data so I can't paste the values in different rows.
use:
=ARRAYFORMULA(IFNA(VLOOKUP(B2:B,
SPLIT(FLATTEN(SPLIT(Sheet1!F2:F, ",")&"×"&Sheet1!G2:G), "×"), 2, )))

How to find the difference in hours between two dates dd/mm/yyyy hh:mm

I have two dates in cells
A1=05.11.2021 18:16
B1=05.11.2021 20:16
I need to find difference in hours between two dates. Result should be (B1-A1)=2 I can't find an answer on the Internet, I ask for help.
use:
=TEXT((DATE(
REGEXEXTRACT(B1, "\d{4}"),
REGEXEXTRACT(B1, "\.(\d+)\."),
REGEXEXTRACT(B1, "^\d+"))+INDEX(SPLIT(B1, " "),,2))-(DATE(
REGEXEXTRACT(A1, "\d{4}"),
REGEXEXTRACT(A1, "\.(\d+)\."),
REGEXEXTRACT(A1, "^\d+"))+INDEX(SPLIT(A1, " "),,2)), "[h]")
arrayformula:
=INDEX(IFNA(TEXT((DATE(
REGEXEXTRACT(B1:B, "\d{4}"),
REGEXEXTRACT(B1:B, "\.(\d+)\."),
REGEXEXTRACT(B1:B, "^\d+"))+INDEX(SPLIT(B1:B, " "),,2))-(DATE(
REGEXEXTRACT(A1:A, "\d{4}"),
REGEXEXTRACT(A1:A, "\.(\d+)\."),
REGEXEXTRACT(A1:A, "^\d+"))+INDEX(SPLIT(A1:A, " "),,2)), "[h]")))
shorter:
=INDEX(IFERROR(1/(1/(TEXT(
REGEXREPLACE(B1:B, "(\d+).(\d+).(\d{4})", "$2/$1/$3")-
REGEXREPLACE(A1:A, "(\d+).(\d+).(\d{4})", "$2/$1/$3"), "[h]")))))
EDIT:
As what #basic mentioned in the above comment, you can format the cell where your output goes or use text with h for hour difference and [h] for the whole duration in hours (got from Cooper's answer). See usage and difference below:
Text:
=text(B1-A1, "h")
or
=text(B1-A1, "[h]")
Update:
Make sure your Date Times uses proper delimiters. / and - are acceptable (e.g. 5/11/2021 18:16:00 or 5-11-2021 18:16:00). (This depends entirely on your locale.)
If you want to show it having . as delimiter, just use a custom Date Time format and use . as its delimiter.
Using custom format:
Actual value vs Display value:
If you don't want to do any changes to the date time and want to have it as text, then replace them using regexreplace before using them in text.
RegexReplace:
=text(REGEXREPLACE(B1, "\.", "/") - REGEXREPLACE(A1, "\.", "/"), "h")
or
=text(REGEXREPLACE(B1, "\.", "/") - REGEXREPLACE(A1, "\.", "/"), "[h]")

How to import price from Bloomberg?

From this website
https://www.bloomberg.com/profile/company/AAGB:MK
I want to extract the value for stock AAGB:MK.
In my Google Sheets, this is my formula.
=IMPORTXML("https://www.bloomberg.com/profile/company/AAGB:MK","//a[#span class='priceText__0feeaba3']")
It fails to extract.
Can someone please help me?
try this:
=REGEXEXTRACT(INDEX(IMPORTDATA(
"https://www.bloomberg.com/profile/company/AAGB:MK"), 100, 1),
"price%22%3A(.*)%2C%22priceChange")

How can I grab the XML data using Google Sheets

Google sheet has a function importxml() to grab data from a webpage, I want to grab the table from https://rss.weather.gov.hk/rss/CurrentWeather.xml, it is an XML with XSL when I view the page source, I find the <td> tag, I try to input
=IMPORTXML("https://rss.weather.gov.hk/rss/CurrentWeather.xml", "//td")
in the cell but it returns #N/A, what is the syntax error I made? Or the content format not acceptable to Google Sheets?
=ARRAYFORMULA({IFERROR(REGEXEXTRACT(TRANSPOSE(SPLIT(INDEX(IMPORTXML(
"https://rss.weather.gov.hk/rss/CurrentWeather.xml", "//*"), 21, 1),
CHAR(10))), "(.*) \d+ degrees ;"), TRANSPOSE(SPLIT(INDEX(IMPORTXML(
"https://rss.weather.gov.hk/rss/CurrentWeather.xml", "//*"), 21, 1),
CHAR(10)))), IFERROR(REGEXEXTRACT(TRANSPOSE(SPLIT(INDEX(IMPORTXML(
"https://rss.weather.gov.hk/rss/CurrentWeather.xml", "//*"), 21, 1),
CHAR(10))), "\d+ degrees ;"))})

Add leading '$' to google charts

I am working with Google Charts. I need to add a '$' before the values on the y-axis as well as the value in the bubbles.
Is there a setting for this?
take care,
lee
UPdate,
Here is the data being used by the charts:
'Month','Semi-Detached in Toronto E04','Semi-Detached in Toronto E08','Condominium Townhouse in Toronto E04','Condominium Townhouse in Toronto E08', ],
['7/2011', 4354000,15305800,6776500,495000],['8/2011', 700000,10514418,7060786,0],['9/2011', 6854800,17805400,12087300,0],['10/2011', 7287400,14248900,16206500,0],['11/2011', 2696245,9733270,12698090,0],['12/2011', 1965800,6054500,8854390,0],['1/2012', 2450968,9012200,5500100,0] ]);
I've tried adding '$' before the values as well as '%24' as suggested before, but both throw syntax errors. And the values cannot be quoted without throwing a Google Charts error '
Data column(s) for axis #0 cannot be of type string×'.
Thanks everyone for your input. I found a question that was 99.9% the same:
How to set tooltips to display percentages to match axis in Google Visualization Line Chart?
Try using %24 which is the urlencoded form for $.
Use:
var formatter = new google.visualization.NumberFormat({prefix: '$'});
Check the example here:
https://developers.google.com/chart/interactive/docs/examples#interaction_example
More details here:
https://developers.google.com/chart/interactive/docs/reference#numberformatter