Looking to take a string along the lines of:
"text": "fkjhsabhfkjhs7g8ydfgd.",
"e": 1541699908958,
"test": true
and only extract the characters between the text field...so end up with only fkjhsabhfkjhs7g8ydfgd.
The length of the text field can vary
Tried this: =REGEXEXTRACT(C2,"""(.*?)""") with no luck
I found that if you escape the double double quotes, that it works. The other examples don't appear to work in Google Sheets regexextract function
=REGEXEXTRACT(C2,"\""(.*?)\""")
An alternative solution could be
=regexextract(C2, "\:\s""(.+?)""")
I'm not sure if Excel does capture groups properly, but if your input has no double quotes inside, you could try:
=REGEXEXTRACT(C2, "[^""]+")
which matches up to the second double quote (eg. matches abc in "abc"d").
Change A1 with your designated cell number and it should work
=REGEXEXTRACT(A1,"""(.*?)""")
Related
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.
I'm trying to do a conditional formatting that matches on the double quote character followed by a zero. i.e.
"0 / 10" : this should match as true
"10 / 10": this should match as false
This regex is incorrect, as it matches on both:
=REGEXMATCH(B:B;"0 /")
I expect to be able to use the formula standard of escaping the " with an extra quote. It accepts this formula syntactically, but does not match:
=REGEXMATCH(B:B;"""0 /")
I tried matching with punctuation characters, no match:
=REGEXMATCH(B:B;"[[:punct:]]0 /")
I can use [digit[ to match the 10/10 case, but ~digit doesn't match the zero with a quote in front of it:
=REGEXMATCH(B:B;"[^[:digit:]]0 /")
I even tried concatenating the specific character, no match:
=REGEXMATCH(B:B;CONCATENATE(CHAR(34), "0 /"))
I'm very confused at this point. If I insert any other special character before the zero, I have no trouble matching it. But it seems like double-quote just isn't treated like a regular character somehow. Does anyone know what I'm doing wrong?
Try
=REGEXMATCH(B2;char(34)&"0 /")
Thanks to Tim for giving me a hint that lead to a solution. My problem was that the text in a cell was part of a formula. So I needed to extract the formula as text (FORMULATEXT) and then it works:
=REGEXMATCH(FORMULATEXT($B1);"""0 /")
Try this in row 1 of a different column:
=arrayformula(if(B:B<>"",iferror(regexmatch(B:B,"""0"),),))
if(B:B<>"" will only process the formula provided Col B has values.
iferror( will ignore numbers in Col B that produce #VALUE!.
"""0" is the regex. The double quote to the left of 0 is doubled up (or char(34)&"0" as per #Mike Steelson).
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)
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.
I am trying to do a calculation of two cells, where one of them contains a number like this: 1 250.
If the number is written like that, and not 1250, then I cannot get the spreadsheet to do any calculations with it. Google suddenly do not treat it as a legit number anymore.
Why not just type 1250 instead of 1 250?
Well, I am getting the cell values from a html import function.
Any good advice on how to get around this?
Try something like this:
=Substitute(A2," ","")
In this formula, A2 is a cell. You are finding any spaces in that cell and then replacing it with a "non-space".
Use the substitute function to transform your number before using it in a formula. For instance, let's say you wanted to multiple F8 by 2, but F8 may contain spaces. You would then do:
=substitute(F8, " ","") * 2
Substitute didn't work form me. But these steps did:
Select one or several columns of data
Press Ctrl + H to get the "Find and Replace" dialog
Make sure "Search using regular expressions" is checked ✅
Enter \s to the "Find" field, and leave "Replace with" empty
Click on the "Replace all" button
Explanation:
\s is a regular expression matching any kind of whitespace character. There may have been some other kind of whitespace in my spreadsheet, not a regular " " (space) character, and that's why regex worked for me, while SUBSTITUTE() didn't.
I've also tried the REGEXREPLACE(A2, "\s", "") function, but it didn't seem to to anything in my case.