Add Double Quotes before and after the string including Lines - google-sheets

I want to add inverted commas before and after the string and Lines by replacing the Comma. I have below string and using this for inverted commas.
Char(34)&A1&Char(34)
But when i add this formula to add lines then it adds double inverted commas. Any solution to this problem will be appreciated.
My formula =CHAR(34)&SUBSTITUTE(A1,",",CHAR(10))&CHAR(34) the string becomes like this
"""Completed BDM 01-24-2019
DDM 10-31-2021
"""
Sheet Link

In your situation, how about the following sample formula?
Sample formula:
=ARRAYFORMULA(Char(34)&TRIM(REGEXREPLACE(REGEXREPLACE(A2:A10," {2,}|, $"," "),",",CHAR(10)))&Char(34))
At first, the multiple spaces and the last comma are replaced with a single space. And the comma is replaced with CHAR(10). And, Char(34) is added to the 1st and last character.
Result:
Reference:
REGEXREPLACE
Added:
From your following replying,
But i just "want" these inverted commas 1 time at beginning and end of the string not twice. When i copy any cell from the formula and paste into the Word document in converts the inverted commas "From this" to ""this"" but i only want "this"
In the current stage, when the line break is included in the cell value, when the cell is copied and pasted, it seems that it becomes """test""". In that case, when you want to copy and paste the cell values like "test" instead of """test""", how about the following sample formula?
=ARRAYFORMULA(IF(REGEXMATCH(REGEXREPLACE(A2:A10,", $",""),","),TRIM(REGEXREPLACE(REGEXREPLACE(A2:A10," {2,}|, $"," "),",",CHAR(10))),Char(34)&TRIM(REGEXREPLACE(A2:A10," {2,}|, $"," "))&Char(34)))
In this sample formula, the double quotes are not shown in the cell. And, the value without the line break is enclosed by ". But when you copy and paste the cell value, the value is enclosed by the single double-quote.

Related

Extract dollar amount in sheets text cell

Ideally what I'm looking for is to get the dollar amount extracted no matter the format.
Sheet link:
https://docs.google.com/spreadsheets/d/1drTPlnQmVTsbUXwJDfQr7DnHjSbnGx-fLthad6KxfM8/edit?usp=sharing
Delete everything from Column B, including the header. Then place the following formula in cell B1:
=ArrayFormula({"Header"; IF(A2:A="",,VALUE(IFERROR(REGEXEXTRACT(A2:A,"\$(\d+\.?\d*)"))))})
You may change the header text within the formula as you like.
If a cell in A2:A is blank, the corresponding cell in B2:B will be left blank as well.
Otherwise REGEXEXTRACT will look for a pattern that begins with a literal dollar sign. The parenthesis within the quotes denote the beginning and end of a capture group (i.e., what will be returned if found) following that literal dollar sign. The pattern \d+\.?\d* means "a group of one or more digits, followed by zero or one literal period symbols, followed by zero or more digits."
IFERROR will cause null to be rendered instead of an error if such a pattern is not able to be extracted.
VALUE will convert the extracted string (or null) to a real number.
If you would prefer that null be returned instead of 0 where no pattern match is found, you can use the following variation of the formula instead:
=ArrayFormula({"Header"; IFERROR(VALUE(IFERROR(REGEXEXTRACT(A2:A,"\$(\d+\.?\d*)"),"x")))})
If your strings may include numbers with comma separators, use the following versions of the above two formulas, respectively:
=ArrayFormula({"Header V1"; IF(A2:A="",,VALUE(IFERROR(REGEXEXTRACT(SUBSTITUTE(A2:A,",",""),"\$(\d+\.?\d*)"))))})
=ArrayFormula({"Header V2"; IFERROR(VALUE(IFERROR(REGEXEXTRACT(SUBSTITUTE(A2:A,",",""),"\$(\d+\.?\d*)"),"x")))})
try:
=INDEX(IFNA(REGEXEXTRACT(A2:A, "\$(\d+.\d+|\d+)")*1))

How can I make quotation marks act as normal text within a regex function?

I'm trying to use regex to extract information from a large text file on google sheets, but within the regex, I'm using quotation marks, and instead of treating everything like the text I want to use, the quotation marks make it so that the regex splits into many different parts. Is there some character I can add to prevent this?
As an example, say I used =REGEXEXTRACT("name"="",""name"="(\w+)"")
It would basically split this into:
REGEXEXTRACT(
"name"
=
""
,
""
name
"="
(\w+)
"")
and would return a formula parse error.
Is there any way I can cancel out certain quotation marks?
Solution:
You can escape double quotes by... another double quote!
So if your first formula argument is name"=" and your second formula argument is "name"="(\w+)", you would use:
=REGEXEXTRACT("name""=""","""name""=""(\w+)""")
Output: (note that I used concatenate to show the expressions)

Combine 2 REGEXREPLACE Formulas Into One

In cell C5, I have a date with dashes ---> 01-31-2013
I just need to remove the dashes, extract only the first 4 digits in the date (in this case, 0131), and append 'Efisd' at the BEGINNING of the string.
So, the end result should look like this ---> Efisd0131
So far, I've been able to remove the dashes, and extract the first 4 digits of the date. But, I can't seem to put append 'Efisd' to the beginning and put it all together into one formula.
Does anyone know how to do this? Thanks for your help.
Here's the sample spreadsheet that you can edit
From just the input date you can get it done with this:
="Efisd"&left(substitute(B5,"-",""),4)
It substitutes the dashes for blanks, gets the left 4 characters, and ads Efisd to the front.
If anyone wants the arrayformula version of this, here it is below. Put formula in very top cell in column, edit the header in between quotes, and change cell values to fit your spreadsheet.
={"Your Header";arrayformula(iferror(if(len(M2:M),"Efisd"&left(substitute(M2:M,"-",""),4),""),))}

Combine Data From Separate Columns with a Delimiter with Arrayformula

This is the example sheet.
Alright, in cell V1!A1 is the formula ={"Languages";ARRAYFORMULA(TRANSPOSE(QUERY(TRANSPOSE(B2:F&","),,COLUMNS(B2:F))))}. I need to combine data from B2:F with the delimiter ,. But now I need to delete the unnecessary delimiters.
In sheet V2, I tried ={"Languages";ARRAYFORMULA(REGEXREPLACE(REGEXREPLACE(TRANSPOSE(QUERY(TRANSPOSE(B2:F&","),,COLUMNS(B2:F))),"(^(,(\s,){4})$)|(^(,\s)+)|(,(\s,)?\s?$)",""),"(,\s,)+\s?",", "))} but it's not consistant and still leaves delimiters in the output.
Is there a better way to do this?
I added a sheet called "Erik Help" which replaces your formula with the following:
=ARRAYFORMULA({"Languages";SUBSTITUTE(TRIM(TRANSPOSE(QUERY(TRANSPOSE(B2:F&" "),,COLUMNS(B2:F))))," ",", ")})
Essentially, instead of appending a comma to elements of the range B2:F, I appended a space. Then I applied TRIM to the results, which will leave no spaces before or after each concatenation and only one between each element. To that, I applied a SUBSTITUTE of the single spaces with a comma-space.

Extract substring after '-' character in Google Sheets

I am using the following formula to extract the substring venue01 from column C, the problem is that when value string in column C is shorter it only extracts the value 1 I need it to extract anything straight after the - (dash) no matter the length of the value text in column c
={"VenueID";ARRAYFORMULA(IF(ISBLANK(A2:A),"",RIGHT(C2:C,SEARCH("-",C2:C)-21)))}
There is a much simpler solution using regular expressions.
=REGEXEXTRACT(A1,".*-(.*)")
In case you are no familiar with Regular Expressions what this means is, get me every string of characters ((.*)) after a dash (-).
Example
Reference
REGEXTRACT
Test regular expressions
Cheat sheet for regular expressions
To answer bomberjackets question in the comment of Raserhin:
To select the part of the string before the "-"
=REGEXEXTRACT(A1,"(.*)-.*")
EXAMPLE
example of code
Adding to your original formula. I think if you'd use RIGHT and inside it reverse the order of the string with ARRAY then that may work.
=Right(A1,FIND("-",JOIN("",ARRAYFORMULA(MID(A1,LEN(A1)-ROW(INDIRECT("1:"&LEN(A1)))+1,1))))-1)
It takes string from the right side up to X number of characters.
Number of character is fetched from reversing the text, then finding
the dash "-".
It adds one more +1 of the text as it will take out so it accounts
for the dash itself, if no +1 is added, it will show the dash on
the extracted string.
The REGEX on the other answer works great too, however, you can control a number of character to over or under trim. E.g. if there is a space after the dash and you would like to always account for one more char.

Resources