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).
Related
In Google Sheets, I'm finding duplicates using the common approach of:
=IF(COUNTIF(A:A,A2)>1,"Duplicate","Unique")
But it is ignoring punctuation marks like '?'
For example, if I have 'wordA' and 'wordA?' it shows them as duplicates when they are not.
Is there any way around this?
The countif() function treats ? as a wildcard that matches any single character. wordA? will match wordA that has a trailing space. To get exact matches only, use filter(), like this:
=if( counta(iferror(filter(A:A, A:A = A2))) > 1, "Duplicate", "Unique" )
See countif().
try:
=INDEX(IF(COUNTIF(A:A&"×", A2&"×")>1, "Duplicate", "Unique"))
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))
I have a google sheet (link) where I'm running a trivial query to find values based on a cell with piped values.
=QUERY(A1:A8;"select A where A matches '"&C2&"'";-1)
The piped values are
word 1|word (1)
The range is
Entries
word (1)
word (2)
word (2)
word (1)
word 1
word 2
word 1
For some reason, I don't get any results which include parentheses ().
It works well with the following query
=QUERY(A1:A8;"select A where A = 'word (1)'";-1)
Are there any limitations with using parentheses () with the matches function?
Thanks in advance.
You will need to escape parenthesis for the query to work
This means that the correct syntax for your C2 cell is
word 1|word \(1\)
You can even use
="word 1|word \(1\)"
Your formula will still be
=QUERY(A1:A8;"select A where A matches '"&C2&"'";-1)
I have a cell in E13 which contains numbers and numbers between brackets.
What I want to acheive is to match the number and copy to another cell and delete the match from E13.
E13
0:08.63 [6]
I want E13 to be
0:08.63
And in M13 I want
6
Based on this example https://support.google.com/docs/answer/3098244?hl=en
=REGEXEXTRACT(A4, "\(([A-Za-z]+)\)")
I tried this in M13
=REGEXEXTRACT(E13,\([[0-9]+]\))
Then based on this SO answer https://stackoverflow.com/a/2403159/461887
=REGEXEXTRACT(E13,\[(.*?)\])
But in both cases I just get an error.
SPLIT by the space:
=SPLIT(E13," ")
REGEX:
=REGEXEXTRACT(E13,"(\S+)\s+\[(\d+)\]")
You are just getting a basic syntax error. The minimal help for REGEXEXTRACT shows that the regexp must be enclosed in double quotes. Your second expression works correctly then:
=REGEXEXTRACT(E13,"\[(.*?)\]")
I am trying to learn Regex and I have scenario where I thought I can use the same. I have a set of strings in the below format(as shown in the table) from which I need to extract each substring around joining operator "and", "or", "not". For eg:- "some column name1 = some value1" as one such substring from first string.
After that I need to extract left hand side string and right hand side string of operators "like", "=", "<", ">". In the above example it would give "some column name1" as one substring and "some value1" as another substring along with operator as "=".
some column name1 = some value1 and some column name2 < another value2 or some column name 3 > value3 not
column name 4 = value4 and name5 = value5
columnA = 324324
columnB like a text
value text
Since I am new to Regex, this is what I have tried till now but it doesn't seem to give me all the values around these operators. Once this works, I am thinking I can apply similar regex with operators as "like", "=", "<", ">" on the resulting substrings to get final output.
(.*?)\b(and|or|not)
When I try the above regex on the first example, this part "name5 = value5" is missing after matching.
(.+?)(and|or|not)(.+)
When I try this one, it matches the first substring but rest of them are matched as a single substring instead of splitting those again.
Please note that I was able to use split operation and give "and|or|not" as separator to get array of substrings however I am trying to see if I can directly get these matched substrings from the given string just for learning regex(This answer says it is possible to do using Regex). I have explored stackoverflow for similar questions but none of the solutions worked in my case. The language in my case is Objective C/Swift.
You may add an end of string anchor $ as an alternative to the delimiters.
(.*?)(?:\b(and|or|not)\b|$)
^^
See the regex demo.
If your string contains line breaks, you must make . match them by adding (?s), a DOTALL modifier, at the pattern start.