I am in a pickle and need some help extracting portion of a string in a google sheet cell.
SM - Lead - LINE ITEM GOES HERE (ABC) - Jan $ 11.75 3,515.00 $ 41,301.25
I am looking to extract the amount after the second dollar ($) sign.
Thank you!
Assuming the second dollar sign is always at the end of the string, you can also try
=regexextract(A2, "[^$\s]+$")
Assuming that the spaces and the format will be the same, you can try the formula below:
=REGEXEXTRACT(A1,"\$ \S+ \S+ \$ (\S+)")
This resulted to:
Related
I'm making a list for buying groceries in Google Sheets and have the following value in cell B4.
0.95 - Lemon Juice
2.49 - Pringle Chips
1.29 - Baby Carrots
9.50 - Chicken Kebab
What I'm trying to do is split using the dash character and combine the costs (0.95+2.49+1.29+9.50).
I've tried to use Index(SPLIT(B22,"-"), 7) and SPLIT(B22,"-") but I don't know how to use only numbers from the split string.
Does someone know how to do this? Here's a sample sheet.
Answer
The following formula should produce the result you desire:
=SUM(ARRAYFORMULA(VALUE(REGEXEXTRACT(SPLIT(B4,CHAR(10)),"(.*)-"))))
Explanation
The first thing to do is to split the entry in B4 into its component parts. This is done by using the =SPLIT function, which takes the text in B4 and returns a separate result every time it encounters a specific delimiter. In this case, that is =CHAR(10), the newline character.
Next, all non-number information needs to be removed. This is relatively easy in your sample data because the numbers always appear to the left of a dash. =REGEXEXTRACT uses a regular expression to only return the text to the left of the dash.
Before the numbers can be added together, however, they must be converted to be in a number format. The =VALUE function is used to convert each result from a text string containing a number to an actual number.
All of this is wrapped in an =ARRAYFORMULA so that =VALUE and =REGEXEXTRACT parse each returned value from =SPLIT, rather than just the first.
Finally, all results are added together using =SUM.
Functions used:
=CHAR
=SPLIT
=REGEXEXTRACT
=VALUE
=ARRAYFORMULA
=SUM
Firstly you can add , symbols start and ends of numbers with below code:
REGEXREPLACE(B4,"([0-9\.]+)",",$1,")
Then split it based of , sign.
SPLIT(A8, ",")
Try below formula (see your sheet)-
=SUM(ArrayFormula(--REGEXEXTRACT(SPLIT(B4,CHAR(10)),"-*\d*\.?\d+")))
I want a function that can replace ANY " " with the ones that we use in greece « ».
For example in A2 i have:
The kid said "lets play" and i said "yes!".
And i want a function that will return:
The kid said «Lets play» and i said «yes!».
(If you dont know where the greek quotation marks are located in the keyboard, then simply copy paste them and insert them in your function: « » )
Thank you!
try:
=REGEXREPLACE(A1, """(.*?)""", "«$1»")
What worked for me:
=REGEXREPLACE(A1,CHAR(34)&"(.*?)"&CHAR(34),"«$1»")
As an alternative to the Sheets formulae already provided, you can also make use of Apps Script:
function replaceQM() {
let ss = SpreadsheetApp.getActiveSheet();
let cell = ss.getRange('A1').getValue().toString();
cell = cell.replace(/"(?=[\w,.?!\)]|$)/g, "«").replace(/(?<=[\w,.?!\)]|^)"/g, "»"); ss.getRange('A2').setValue(cell);
console.log(cell)
}
The snippet above makes use of regex in order to replace the quotation marks. The first replace method is used to find any quotation marks at the beginning of a word and the second replace is used to find any quotation marks at the end of a word, taking into account the punctuation marks.
Therefore, if we run the script above, we'll be getting the following results:
Reference
Google Apps Script;
String.prototype.replace();
Regex.
I have a list of numbers in a few formats that may or may not include a dot and a comma. The numbers are locked in a string. For example:
hello 1,000 goodbye
hola 2,000.12 ciao
Hallo 3000.00 Auf Wiedersehen
How can I extract the numbers?
I don't care if the comma is added but the dot is obviously important.
I need the regular_expression to be used in REGEXEXTRACT (and the rest of the REGEX formulas.
The output should be:
1000
2000.12
3000.00
Supposing that your raw data is in A2:A, use this in B2 (or the second cell) of an otherwise empty column:
=ArrayFormula(IF(A2:A="",,IFERROR(VALUE(REGEXEXTRACT(A2:A,"\d[\d,\.]*\d")))))
The REGEX portion reads, in plain English, "Extract any portion that starts with a digit followed by any number of digits, commas or periods (or none of these) and ends with a digit."
You will likely want to apply Format > Number > Currency to the results column.
I know how to split text using other delimiters such as a comma, equal sign etc. I am having trouble for examples that require a number delimiter.
A typical split formula that uses a comma delimiter would look like this:
=SPLIT(A1, ",")
I am struggling with splitting text that looks something like this. The delimiter here is a number.
This is a random text of 20 characters but could be 30 characters as well.
Output should be
This is a random text of | 20 | characters but could be | 30 | characters as well.
Please help. Thanks
Try the following:
=SPLIT(REGEXREPLACE(A1,"\d+","|$0|"),"|")
Maybe better, to remove spaces:
=SPLIT(REGEXREPLACE(A1,"\s*(\d+)\s*","|$1|"),"|")
I'm trying to split a cell on the 2nd space character. Is this possible? Or is it just possible to split on a space character?
LeBron James SF ORL # CLEThu 7:00pm
LeBron James SF ORL # CLEThu 7:00pm
Please try regular expression:
=REGEXEXTRACT(A1,"^([^ ]+ [^ ]+) (.*)")
(...) (...) is to find 2 groups on a string
^ at the beginning means to look at the start of a string
[^ ]+ means 1+ no space char.
.* means any number of chars
References:
RegexExtract
Regex Syntax
You can use il of individual pieces of the split. For example if 'LeBron James SF ORL # CLEThu 7:00pm' is in A1. In B1 put this:
=index(split(A1," "),0,1)&" "&index(split(A1," "),0,2)
It will return 'LeBron James'. In C1 put:
=index(split(A1," "),0,3)&" "&index(split(A1," "),0,4)&" "&index(split(A1," "),0,5)&" "&index(split(A1," "),0,6)&" "&text(index(split(A1," "),0,7),"hh:mm am/pm")
It will return 'SF ORL # CLEThu 07:00 PM'. Note the use of text to return the time correctly.
A simple way is to SUBSTITUTE the second instance of a space with a character not otherwise in service (I chose £), then SPLIT on that character:
=split(substitute(A1," ","£",2),"£")