REGEX: Transpose each word from a google sheet cell and put them one under the other (rows) - regex

I need to extract each word (phrase) within a cell in google sheets and put each one under the other in a column (row for each one).
I have a regex code that works when testing it, but I cannot do it work in google sheet the same code. Any ideas?

You can just do
=SUBSTITUTE(A1," ",char(10))
or
=transpose(split(A1," "))

You don't really need regex for this. You can use Transpose and split methods of google sheets.
Example:
In sheets in A1 put your text then in B1 copy this =TRANSPOSE(SPLIT(A1," "))

Update: this answer does not meet all requirements as it puts all results in one cell.
The ASCII character numbers need to be used instead of \r\n that you would expect from other tools.
Carriage return has number 13 and line feed has number 10:
=REGEXREPLACE(A1, "\s", CONCAT(CHAR(13), CHAR(10)))

Related

Google Sheets multiple search and replace from a list

I already found this solution, but unfortunately I can't comment or ask a question in this thread.
https://stackoverflow.com/a/47685929/19554304
Is there a way to change the script from the solution so that it is possible to check multiple words for a replacement. For example: Check if the text contains the words A or B and replace them with C.
Thx
Check if the text contains the words A or B and replace them with C.
You can solve it vía formula like this:
=reduce(C2,SEQUENCE(COUNTA(A:A)),LAMBDA(a,r,REGEXREPLACE(a,"\b("&INDEX(A:A,r)&")\b",INDEX(B:B,r,))))
You put the values separated by "|" in Column A and its replacements in column B. For example: "car|Moto"
Let me know if it is useful! You can use it as ARRAYFORMULA too by wrapping it in ARRAYFORMULA and changing C2 with the whole range of C column

Regexreplace forumula in Google sheets to replace multiple matches in multiple lines

I have the following text in Cell A1 in google sheets with multiple linebreaks:
A paragraph is a series of sentences
that are organized and coherent, Zing
and are all related to a single topic.
Almost every piece of writing you do
that is longer than a few sentences Zing
should be organized into paragraphs.Zing
... One of the most important of these
is a topic sentence. Zing
And I would need to extract all the lines that ends with the word Zing so the output becomes(following is the expected output):
that are organized and coherent, Zing
that is longer than a few sentences Zing
should be organized into paragraphs.Zing
is a topic sentence. Zing
First i tried using regexextract formula "=REGEXEXTRACT(A1,".*Zing")", but unfortunately it returns only the 1st occurence that are organized and coherent, Zing
Then I tried using regexreplace to replace all other lines that doesnt contain or ends with Zing, but it did not work.
=REGEXREPLACE(A1, ".*Zing", ",")
This returned:
"A paragraph is a series of sentences
,
and are all related to a single topic.
Almost every piece of writing you do
,
,
... One of the most important of these
,"
but I want the missing lines, how to exclude the above and to extract only the missed lines
I would need a formula in excel or googlesheets to match the expected output
In your situation, how about the following sample formula?
Sample formula:
=JOIN(CHAR(10),REGEXEXTRACT(A1,REGEXREPLACE(A1,"(.*Zing)","($1)")))
When you want to put each line to each row, you can also use the following formula.
=TRANSPOSE(REGEXEXTRACT(A1,REGEXREPLACE(A1,"(.*Zing)","($1)")))
Result:
References:
REGEXREPLACE
REGEXEXTRACT
JOIN

How can I extract specific patterns from a string?

I currently have a dataset filled with the following pattern:
My goal is to get each value into a different cell.
I have tried with the following formula, but it's not yielded the results I am looking for.
=SPLIT(D8,"[Stock]",FALSE,FALSE)
I would appreciate any guidance on how I can get to the ideal output, using Google Sheets.
Thank you in advance!
I will assume here from your post that your original data runs D8:D.
If you want to retain [Stock] in each entry, try the following in the Row-8 cell of a column that is otherwise empty from Row 8 downward:
=ArrayFormula(IF(D8:D="",,TRIM(SPLIT(REGEXREPLACE(D8:D&"~","(\[Stock\]).","$1~"),"~",1,1))))
If you don't want to retain [Stock] in each entry, use this version:
=ArrayFormula(IF(D8:D="",,TRIM(SPLIT(REGEXREPLACE(D8:D&"~","\[Stock\].","~"),"~",1,1))))
These formulas don't function based on using any punctuation at all as markers. They also assure that you don't wind up with blank (and therefore unusable) cells interspersed for ending SPLITs.
, only used in the separator
=ARRAYFORMULA(SPLIT(D8:D,", ",FALSE))
, used also in each string ([stock] will be replaced)
=ARRAYFORMULA(SPLIT(D8:D," [Stock], ",FALSE))
, used also in each string ([stock] will not be replaced)
=ArrayFormula(SPLIT(REGEXREPLACE(M9:M11,"(\[Stock\]), ","$1♦"),"♦"))
use:
=INDEX(TRIM(IFNA(SPLIT(D8:D; ","))))

Is there a method for dividing an Address string into 3 separate strings using regex

I am currently working on a project that requires me to divide an address into its street number, its street name, and if it has a suite, into its suite name.
EX: 1360 WHITE OAK RD STE F -----> 1360 | White Oak RD | STE F
I am currently using google sheet and using the =regexextract() functionality that uses Regex to parse the string into different columns. This is how I am currently dividing the number and the street (given the full address is in column B.
=ArrayFormula(REGEXEXTRACT(B1:B,"[0-9]*")) ---->gets the number EX:(1360)
=ArrayFormula(REGEXEXTRACT(B1:B," [a-zA-Z0-9 ]+")) ---->gets the street address including the suite number with a white space at the begining EX:( WHITE OAK RD STE F)
The question I am struggling with is how do I remove the white space from the 2nd formula and also prevent it from getting the suite text (which always starts with STE). Lastly what would be a formula for grabbing the suite text and number.
Thanks and I appreciate any help you can give!
The formula provided by MonkeyZeus works perfectly giving no issues whatsoever.
In case though you have your results in adjacent columns you can use a single formula on every row like
=SPLIT(REGEXREPLACE(B1,"([0-9]+) (.+) (STE.*)","$1♣︎$2♣︎$3"),"♣︎")
Or even use an Arrayformula to get your results for an entire column
=ArrayFormula(IFERROR(SPLIT(REGEXREPLACE(B1:B,"([0-9]+) (.+) (STE.*)","$1♣︎$2♣︎$3"),"♣︎")))
What the formula does
using parenthesis () we divide the text into 3 groups $1, $2, $3
$1♣︎$2♣︎$3 adding the character ♣︎ (could be any character that does not interfere with the formula) we prepare uor text for the SPLIT function
we split our now formed into groups text, to adjacent columns wherever ♣︎ is found
The Arrayformula applies all the above to every single row in column B while IFERROR makes sure we don't get any errors (like when empty cells are found).
Functions used:
ArrayFormula
IFERROR
SPLIT
REGEXREPLACE
For Google Sheets you could use the following 3 formulas:
=REGEXEXTRACT(B1,"^[0-9]*")
=REGEXREPLACE(B1,"^[0-9\s]*|\s*STE.*$", "")
=REGEXEXTRACT(B1,"STE.*$")
I would have used lookbehinds but they are not universally supported in all browsers (yet).
I'm not a Google Sheets expert so I've opted to remove ArrayFormula and replace the B1:B with just B1 since they seemed superfluous.

Google Sheets regexextract multiple text strings from a cell

I am trying to extract the hashtag info from a twitter data cell in google sheets.
We can call this Cell A1:
[{"text":"QOTD","indices":[13,18]},{"text":"CSEC4CG","indices":[87,95]},{"text":"myCSEC","indices":[96,103]},{"text":"Connecticut","indices":[104,116]},{"text":"GiveBack","indices":[117,126]},{"text":"COVID19","indices":[127,135]}]
In a perfect situation I would be able to produce this in another cell extracted from A1:
#QOTD #CSEC4CG #myCSEC #Connecticut #Giveback #COVID19
I am lost how to do it using REGEXTRACT. I assume this is the best method, but any that gets the job done is good.
Thank you for any help!
You want to achieve the following conversion using the built-in functions in Google Spreadsheet.
From
[{"text":"QOTD","indices":[13,18]},{"text":"CSEC4CG","indices":[87,95]},{"text":"myCSEC","indices":[96,103]},{"text":"Connecticut","indices":[104,116]},{"text":"GiveBack","indices":[117,126]},{"text":"COVID19","indices":[127,135]}]
To
#QOTD #CSEC4CG #myCSEC #Connecticut #Giveback #COVID19
If my understanding is correct, how about this answer?
Sample formula:
=TRIM(REGEXREPLACE(REGEXREPLACE(A1,"\[|\]|,",""),"{""text"":""(.+?)""""indices"":.+?}"," #$1"))
In this case, it supposes that the input value is put in the cell "A1".
The flow is as follows.
Replace \[|\]|, with "" using REGEXREPLACE.
Replace {""text"":""(.+?)""""indices"":.+?} with " #$1" using REGEXREPLACE.
The top space is removed with TRIM.
Result:
References:
REGEXREPLACE
TRIM