extracting values based on regex - google-sheets

I have a column which has urls, So below are the values of the column
https://www.example.com/jasja
https://www.example.com/jasdqw?new=exact
So what I want to extract is before the question mark and after the last slash
So here my output in the column should be
jasja
jasdqw
How can I get this using Regex
Tried =REGEXEXTRACT(C2:C16, SPLIT()), but don't know how to use this
Any help is appreciated

We can use REGEXEXTRACT with a capture group:
=REGEXEXTRACT(C2, "/([^/]+?)(?:\?|$)")
Here is a regex demo.

You could also try
=RegexExtract(A1,".*/(.*?)\?")

Related

Extract String via google sheet formular

I have this string:
localhost,GEWTESTID,something,else
The text can be like this, but it can also have fewer values and the order can also be different, like:
GEWTESTID,yesnomaybe
I want to extract GEWTESTID.
GEWTESTID always starts with GEW
and after GEW always 6 chars following.
I tried with SEARCH and LEFT but I can't get the result I want.
Thank you!
try:
=REGEXEXTRACT(A1; "GEW.{6}")

Regualr expression for google Sheet Find and Replace

I have some rows in some columns contains something like
#Invalid Ref: 234566
#Invalid Ref: 123445
#Invalid Ref: 235678
I am trying to use find and replace by regular expression to find any row that contains any of the above and replace it with empty
what is the best regular expression I can use?
If the last numbers are always six digits, this should work. See google's explanation for Regex Find Replace for more examples.
^#Invalid Ref: [0-9]{6}$

Cannot use nested IF for CONCATENATE function

I have a column of data and need to use CONCATENATE to combine them as a string.
=CONCATENATE("{",char(34),0,char(34),":",B2,char(34),
IF(A3="Yes",CONCATENATE(",",char(34),1,char(34),":",B3),
IF(A4="Yes",CONCATENATE(",",char(34),2,char(34),":",B4),
IF(A5="Yes",CONCATENATE(",",char(34),1,char(34),":",B5),
IF(A6="Yes",CONCATENATE(",",char(34),1,char(34),":",B6))))),"}")
However, it only combines the first 2 data. Please help.
Demo sheet: https://docs.google.com/spreadsheets/d/1-xZr2SC2t2E5QKtmTD1kQFr-K8GgJjIHL83Wqr6xYF8/edit#gid=0
Try this:
="{"&JOIN(",",FILTER(CHAR(34)&SEQUENCE(5,1,0)&CHAR(34)&":"&B2:B6,A2:A6="Yes"))&"}"

Splitting a string to all it's characters

This should have been simple but I can't find a workaround. I want to split a string into its characters.
e.g. dog will be sepearted to:
d
o
g
The problem is I can't put an empty character as a delimiter in the SPLIT function.
What am I missing?
Also
=ArrayFormula(mid(A1,sequence(1,len(A1)),1))
Something like this ?
=split(regexreplace(A2, "(.)", "$1_"), "_")
or if you'd want an arrayformula to process a column at once
=ArrayFormula(if(len(A2:A), split(regexreplace(A2:A, "(.)", "$1_"), "_"),))
Reference
More info on how this works? Check this link.
Try the following
=SPLIT(REGEXREPLACE(O13,"(.)","$1"&"-"),"-",1,1)

Sheets: use FILTER for multiple strings instead of exact match only?

I'm trying to SUM column C based on the contents of columns A and B. Like this:
=sum(filter(C:C, (A:A="Safari")*(B:B="10.0.1")))
The above formula works. The FILTER function works as an exact match for "Safari" and "10.0.1" for columns A and B respectively.
The problem is... this only captures an exact match: "10.0.1". I need to capture multiple strings e.g. "10.0.1", "10.0.2", "10.0.3", etc.
If helpful, here's an example sheet.
I'm not sure if regex can be used in combination with a filter function. In any case, I've tried hard and failed spectacularly. So... how best to filter for multiple strings instead of exact match only?
=SUMIFS(C:C,A:A,"Safari",B:B,"10.0.*")
Please try:
=filter(C:C, (A:A="Safari")*(REGEXMATCH(B:B, "10\.0\..*")))
Notes:
filter is an arrayformlula and it has a great property: it converts all the formulas inside it into array formulas
"10.0..*" is a regex for your match. "\." will match a dot, ".*" will match any sequence of chars. Please see more syntax here.

Resources