How to Extract Substring in Google Sheets
To extract a substring in Google Sheets, you can use various functions like LEFT, RIGHT, MID, and REGEXEXTRACT. These functions allow you to extract specific parts of a text string based on the position or a pattern.
Here are the instructions for using some of these functions:
- LEFT function: The LEFT function extracts a substring from the beginning of a text string.
Syntax: =LEFT(text, [num_chars])
- text: The original text string from which you want to extract the substring.
- num_chars: The number of characters you want to extract from the beginning of the text string. This is an optional parameter; if omitted, it defaults to 1.
- RIGHT function: The RIGHT function extracts a substring from the end of a text string.
Syntax: =RIGHT(text, [num_chars])
- text: The original text string from which you want to extract the substring.
- num_chars: The number of characters you want to extract from the end of the text string. This is an optional parameter; if omitted, it defaults to 1.
- MID function: The MID function extracts a substring from a specific position within a text string.
Syntax: =MID(text, start_position, num_chars)
- text: The original text string from which you want to extract the substring.
- start_position: The position within the text string where you want to start extracting the substring.
- num_chars: The number of characters you want to extract.
- REGEXEXTRACT function: The REGEXEXTRACT function extracts a substring based on a regular expression pattern.
Syntax: =REGEXEXTRACT(text, regular_expression)
- text: The original text string from which you want to extract the substring.
- regular_expression: The regular expression pattern to match the desired substring.
Example
Let's say we have the following text string in cell A1: Google Sheets is amazing!
- Extract the first 6 characters using the LEFT function:
=LEFT(A1, 6)
- this will returnGoogle
. - Extract the last 8 characters using the RIGHT function:
=RIGHT(A1, 8)
- this will returnamazing!
. - Extract 5 characters starting from the 8th character using the MID function:
=MID(A1, 8, 5)
- this will returnSheet
. - Extract the word between "Google" and "is" using the REGEXEXTRACT function:
=REGEXEXTRACT(A1, "Google (.+?) is")
- this will returnSheets
.
Did you find this useful?