search
HomeTopicsexcelExtract data from Google Sheets: certain text from strings, URLs from links, and more

This next bit of our operations with text in spreadsheets is devoted to extraction. Find out ways to extract various data — text, characters, numbers, URLs, email addresses, date & time, etc. — from various positions in multiple Google Sheets cells at once.

Google Sheets formulas to extract text and numbers from strings

Formulas in Google Sheets are everything. While some combos add text & numbers and remove various characters, some of them also extract text, numbers, separate characters, etc.

The easiest functions to deal with when you're about to take out data from Google Sheets cells are LEFT, RIGHT, and MID. They get any data by position.

Extract data from the beginning of cells in Google Sheets

You can easily pull out the first N characters using the LEFT function:

LEFT(string,[number_of_characters])
  • string is the text where you want to extract data from.
  • number_of_characters is the number of characters to take out starting from the left.

Here's the simplest example: let's take out the country codes from the phone numbers:

Extract data from Google Sheets: certain text from strings, URLs from links, and more

As you can see, country codes take 6 symbols at the beginning of cells, so the formula you need is:

=LEFT(A2,6)

Extract data from Google Sheets: certain text from strings, URLs from links, and more

Tip. ArrayFormula will make it possible to get 6 characters from the entire range at once:

=ArrayFormula(LEFT(A2:A7,6))

Extract data from Google Sheets: certain text from strings, URLs from links, and more

Extract data from the end of cells in Google Sheets

To pull out the last N characters from cells, use the RIGHT function instead:

RIGHT(string,[number_of_characters])
  • string is still the text (or a cell reference) to extract data from.
  • number_of_characters is also the number of characters to take from the right.

Let's get those country names from the same phone numbers:

Extract data from Google Sheets: certain text from strings, URLs from links, and more

They take only 2 characters and that's exactly what I mention in the formula:

=RIGHT(A2,2)

Extract data from Google Sheets: certain text from strings, URLs from links, and more

Tip. ArrayFormula will also help you extract data from the end of all Google Sheets cells at once:

=ArrayFormula(RIGHT(A2:A7,2))

Extract data from Google Sheets: certain text from strings, URLs from links, and more

Extract data from the middle of cells in Google Sheets

If there are functions to extract data from the beginning and the end of cells, there must be a function to extract data from the middle as well. And yes — there is one.

It's called MID:

MID(string, starting_at, extract_length)
  • string — the text where you want to take out the middle part from.
  • starting_at — the position of the character from which you want to start getting the data.
  • extract_length — the number of characters you need to pull out.

By the example of the same phone numbers, let's find the phone numbers themselves without their country codes and country abbreviation:

Extract data from Google Sheets: certain text from strings, URLs from links, and more

As the country codes end with the 6th character and the 7th is the dash, I will pull numbers starting from the 8th digit. And I'll get 8 digits in total:

=MID(A2,8,8)

Extract data from Google Sheets: certain text from strings, URLs from links, and more

Tip. Changing one cell to the entire range and wrapping it in ArrayFormula will provide you with the result for each cell at once:

=ArrayFormula(MID(A2:A7,8,8))

Extract data from Google Sheets: certain text from strings, URLs from links, and more

Sometimes extracting text by position (as shown above) is not an option. The required strings may reside in any part of your cells and consist of a different number of characters forcing you to create different formulas for each cell.

But Google Sheets wouldn't be Google Sheets if it didn't have other functions that would help to extract text from strings.

Whenever you want to extract data that precedes a certain text, use LEFT SEARCH:

  • LEFT is used to return a certain number of characters from the beginning of cells (from their left)
  • SEARCH looks for certain characters/strings and gets their position.

Combine these — and LEFT will return the number of characters suggested by SEARCH.

Here's an example: how do you extract textual codes before each 'ea'?

Extract data from Google Sheets: certain text from strings, URLs from links, and more

This is the formula that will help you in similar cases:

=LEFT(A2,SEARCH("ea",A2)-1)

Extract data from Google Sheets: certain text from strings, URLs from links, and more

Here's what happens in the formula:

  1. SEARCH("ea",A2) looks for 'ea' in A2 and returns the position where that 'ea' starts for each cell — 10.
  2. So 10th position is where 'e' resides. But since I want everything right before 'ea', I need to subtract 1 from that position. Otherwise, 'e' will be returned as well. So I get 9 eventually.
  3. LEFT looks at A2 and gets the first 9 characters.

Extract data after the text

There are also means to get everything after a certain text string. But this time, RIGHT won't help. Instead, REGEXREPLACE takes its turn.

Tip. REGEXREPLACE uses regular expressions. If you're not ready to deal with them, there's a much easier solution described below. REGEXREPLACE(text, regular_expression, replacement)

  • text is a string or a cell where you want to make changes
  • regular_expression is the combination of characters that stands for a part of the text that you're looking for
  • replacement is whatever you want to get instead of that text

So, how do you use it to extract data after a certain text — 'ea' in my example?

Extract data from Google Sheets: certain text from strings, URLs from links, and more

Easy — using this formula:

=REGEXREPLACE(A2,"(.*)ea(.*)","$2")

Extract data from Google Sheets: certain text from strings, URLs from links, and more

Let me explain how this formula works exactly:

  1. A2 is a cell I'm extracting the data from.
  2. "(.*)ea(.*)" is my regular expression (or you can call it a mask). I look for 'ea' and put all other characters into brackets. There are 2 groups of characters — everything before 'ea' is the first group (.*) and everything after 'ea' is the second one (.*). The entire mask itself is put to double-quotes.
  3. "$2" is what I want to get — the second group (hence its number 2) from the previous argument.

Tip. All characters used in regular expressions are collected on this special page.

Extract numbers from Google Sheets cells

What if you want to extract only numbers when their position and whatever goes before & after doesn't matter?

Masks (a.k.a. regular expressions) will also help. In fact, I'll take the same REGEXREPLACE function and change the regular expression:

=REGEXREPLACE(A2,"[^[:digit:]]", "")

Extract data from Google Sheets: certain text from strings, URLs from links, and more

  1. A2 is a cell where I want to get those numbers from.
  2. "[^[:digit:]]" is a regular expression that takes everything but digits. That ^caret symbol is what makes an exception for digits.
  3. "" replaces everything except numeric characters with "nothing". Or, in other words, removes it entirely, leaving only numbers in cells. Or, extracts numbers :)

Tip. The following formula return the same result: extract only digits from cells:

=REGEXREPLACE(A2,"[^0-9]", "") =REGEXREPLACE(A2,"[^\d]", "")

Extract text ignoring numbers and other characters

In a similar fashion, you can take out only alphabetic data from Google Sheets cells. The contraction for the regular expression that stands for text is called accordingly — alpha:

=REGEXREPLACE(A2,"[^[:alpha:]]", "")

Extract data from Google Sheets: certain text from strings, URLs from links, and more

This formula takes everything but letters (A-Z, a-z) and literally replaces it with "nothing". Or, to put it in another way, takes out only letters.

Formula-free ways to extract data from Google Sheets cells

When it comes to extracting links from Google Sheets cells, formulas won't help. There are 3 other ways however to get those links out of cells.

Hover your mouse over a cell with a hyperlink. You'll see a website preview with 3 settings. Go for Copy link:

Extract data from Google Sheets: certain text from strings, URLs from links, and more

Then just paste that URL from the clipboard into an empty cell:

Extract data from Google Sheets: certain text from strings, URLs from links, and more

Easy-peasy! Yet, you will have to repeat this for every single cell where you'd like to extract those URLs from as the solution doesn't work for cells in batch:

Extract data from Google Sheets: certain text from strings, URLs from links, and more

Tip. To extract links from multiple cells in Google Sheets in one go, use the tool described below.

This one is similar to the method above. When you hover the mouse over the link, click Edit link rather than Copy:

Extract data from Google Sheets: certain text from strings, URLs from links, and more

You will get a chance to preview the URL itself and maybe copy its certain part if that's what you're up to:

Extract data from Google Sheets: certain text from strings, URLs from links, and more

Once you copy the needed part of the URL, paste it to another cell. Repeat for each Google Sheets cell where you need to extract links from:

Extract data from Google Sheets: certain text from strings, URLs from links, and more

Tip. To extract links from multiple cells in Google Sheets at once, use the tool from the next example.

If you need to extract multiple URLs from multiple hyperlinks in Google Sheets in one go, this will be an indispensable tool for you.

Extract add-on from the Power Tools collection has all the necessary settings for the job.

You just select the range with all the hyperlinks (you can even select several non-adjacent ranges by holding the Ctrl key), open the Extract links group in Power Tools, tweak the settings and click Extract:

Extract data from Google Sheets: certain text from strings, URLs from links, and more

Our Power Tools is perfect to extract other types of data as well. Let me show you.

Extract different types of data using Power Tools add-ons

The Extract tool from Power Tools does exactly what you've come looking for in this article — extracts different types of data from Google Sheets cells.

User-friendly settings

All the cases I've covered above are not just solvable with the add-on. The tool is user-friendly so all you need to do is select the range you want to process and tick off the required checkboxes. No formulas, no regular expressions.

Remember this section of this article with REGEXREPLACE and regular expressions? Here's how simple it is for the add-on:

Extract data from Google Sheets: certain text from strings, URLs from links, and more

Extra-options

As you can see, there are some extra options (just checkboxes) that you can quickly turn on/off to get the most precise result:

  1. Get the strings of the required text case only.
  2. Pull out all occurrences from each cell and place them in one cell or separate columns.
  3. Insert a new column with the result to the right of the source data.
  4. Clear the extracted text from the source data.

Extract different data types

Not only Power Tools extracts data before/after/between certain text strings and the first/last N characters; but it also takes out the following:

  1. Numbers along with their decimals keeping the decimal/thousands separators intact:

    Extract data from Google Sheets: certain text from strings, URLs from links, and more

  2. N characters starting from a certain position in a cell.
  3. Hyperlinks (text link), URLs (link), email addresses.

Extract any string of data from everywhere

There's also an option to set up your own exact pattern and use it for the extraction. Extract by mask and its wildcard characters — * and ? — do the trick:

  • For example, you can bring out everything between the brackets using the following mask: (*)
  • Or get those SKUs that have only 5 numbers in their ids: SKU?????
  • Or, as I show on the screenshot below, pull everything after each 'ea' in each cell: ea*

Extract data from Google Sheets: certain text from strings, URLs from links, and more

Extract date and time from timestamps

As a bonus, there's a smaller tool that will extract date and time from timestamps — it's called Split Date & Time.

Although it was created to split timestamps in the first place, it's perfectly capable of getting one of the desired units individually:

Extract data from Google Sheets: certain text from strings, URLs from links, and more

Just select one of the checkboxes depending on what you want to extract — date or time — from timestamps in Google Sheets and hit Split. The required unit will be copied over to a new column (or it will replace the original data if you select the last checkbox as well):

Extract data from Google Sheets: certain text from strings, URLs from links, and more

All these Extract tools are part of the Power Tools collection for Google Sheets.

Once you install it to get any data from Google Sheets cells, it's got you covered completely. If not, please leave a comment and we'll help you out :)

The above is the detailed content of Extract data from Google Sheets: certain text from strings, URLs from links, and more. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
MEDIAN formula in Excel - practical examplesMEDIAN formula in Excel - practical examplesApr 11, 2025 pm 12:08 PM

This tutorial explains how to calculate the median of numerical data in Excel using the MEDIAN function. The median, a key measure of central tendency, identifies the middle value in a dataset, offering a more robust representation of central tenden

Google Spreadsheet COUNTIF function with formula examplesGoogle Spreadsheet COUNTIF function with formula examplesApr 11, 2025 pm 12:03 PM

Master Google Sheets COUNTIF: A Comprehensive Guide This guide explores the versatile COUNTIF function in Google Sheets, demonstrating its applications beyond simple cell counting. We'll cover various scenarios, from exact and partial matches to han

Excel shared workbook: How to share Excel file for multiple usersExcel shared workbook: How to share Excel file for multiple usersApr 11, 2025 am 11:58 AM

This tutorial provides a comprehensive guide to sharing Excel workbooks, covering various methods, access control, and conflict resolution. Modern Excel versions (2010, 2013, 2016, and later) simplify collaborative editing, eliminating the need to m

How to convert Excel to JPG - save .xls or .xlsx as image fileHow to convert Excel to JPG - save .xls or .xlsx as image fileApr 11, 2025 am 11:31 AM

This tutorial explores various methods for converting .xls files to .jpg images, encompassing both built-in Windows tools and free online converters. Need to create a presentation, share spreadsheet data securely, or design a document? Converting yo

Excel names and named ranges: how to define and use in formulasExcel names and named ranges: how to define and use in formulasApr 11, 2025 am 11:13 AM

This tutorial clarifies the function of Excel names and demonstrates how to define names for cells, ranges, constants, or formulas. It also covers editing, filtering, and deleting defined names. Excel names, while incredibly useful, are often overlo

Standard deviation Excel: functions and formula examplesStandard deviation Excel: functions and formula examplesApr 11, 2025 am 11:01 AM

This tutorial clarifies the distinction between standard deviation and standard error of the mean, guiding you on the optimal Excel functions for standard deviation calculations. In descriptive statistics, the mean and standard deviation are intrinsi

Square root in Excel: SQRT function and other waysSquare root in Excel: SQRT function and other waysApr 11, 2025 am 10:34 AM

This Excel tutorial demonstrates how to calculate square roots and nth roots. Finding the square root is a common mathematical operation, and Excel offers several methods. Methods for Calculating Square Roots in Excel: Using the SQRT Function: The

Google Sheets basics: Learn how to work with Google SpreadsheetsGoogle Sheets basics: Learn how to work with Google SpreadsheetsApr 11, 2025 am 10:23 AM

Unlock the Power of Google Sheets: A Beginner's Guide This tutorial introduces the fundamentals of Google Sheets, a powerful and versatile alternative to MS Excel. Learn how to effortlessly manage spreadsheets, leverage key features, and collaborate

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment