+ Reply to Thread
Results 1 to 6 of 6

How to extract a substring between 2 separators

  1. #1
    Registered User
    Join Date
    02-11-2022
    Location
    France
    MS-Off Ver
    2021
    Posts
    10

    Red face How to extract a substring between 2 separators

    Hello,

    I have a list of records which looks like this:

    119619 __xxxx__ 33607167068,Blue,Low,France
    1238619 __xxxx__ 33792157173,Red,High,France
    2109 __xxxx__ 33610617369,Green,Low,France
    12954615 __xxxx__ 33798276051,Blue,Low,France
    182607 __xxxx__ 33698166266,Green,High,France

    [ID] __xxxx__ [phone number],[Color],[Price level],[Country]

    I want to extract the phone number of each line. My problem is that the phone number is between two different types of separators: "__xxxx__" and ",".

    Do you know the right formula to do this?

  2. #2
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    43,996

    Re: How to extract a substring between 2 separators

    If you are using a PC (as opposed to a mac), you can use:

    =FILTERXML("<A><B>"&SUBSTITUTE(SUBSTITUTE(A2," ",","),",","</B><B>")&"</B></A>","//B[3]")
    Attached Files Attached Files
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU.

    Temporary addition of accented to illustrate ongoing problem to the TT: L? fh?ile P?draig sona dhaoibh

  3. #3
    Valued Forum Contributor Haluk's Avatar
    Join Date
    02-14-2019
    Location
    Turkiye
    MS-Off Ver
    2010 - 64 Bit on Windows-11 (22 H2) 64 Bit
    Posts
    1,149

    Re: How to extract a substring between 2 separators

    An alternative is using a classical formula as;

    Please Login or Register  to view this content.
    You may need to change semicolons to commas depending on your local settings.


    Note: If you use Libre Office, its simple as;

    Please Login or Register  to view this content.
    and in Google Sheets;

    Please Login or Register  to view this content.
    Last edited by Haluk; 02-21-2022 at 05:44 AM.

  4. #4
    Registered User
    Join Date
    02-11-2022
    Location
    France
    MS-Off Ver
    2021
    Posts
    10

    Re: How to extract a substring between 2 separators

    Hi Glenn, Haluk,

    Thanks a lot! Actually, I prefer to use Google Sheets, and the formula "=REGEXEXTRACT(A1,"\s(\d+)")" works perfectly, thanks!

    However, I do not understand this formula. What does the code "\s(\d+)" stand for? I though that the formula would contain the separators "__xxxx__" and ",". It seems it is not the case. Can you explain me why? (if this is not too much to ask)

  5. #5
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    43,996

    Re: How to extract a substring between 2 separators

    You did not mention google sheets in your opening post. I have never used Google sheets. I will move this thread to the correct sub-forum.

  6. #6
    Valued Forum Contributor Haluk's Avatar
    Join Date
    02-14-2019
    Location
    Turkiye
    MS-Off Ver
    2010 - 64 Bit on Windows-11 (22 H2) 64 Bit
    Posts
    1,149

    Re: How to extract a substring between 2 separators

    Hi Laura,

    The formula I offered for Google Sheets, uses the "Regular Expressions" method (also the formula for Libre Office)

    "\s(\d+)" part of the formula is the "pattern" to look for in cell A1 where "\s" denotes a "space character" just before a group of digits which is modelled as "(\d+)".

    The parentheses' are used to make a group where "\d" denotes a single digit but if you add a "+" sign, then you tell the formula to look for a group of digits followed by a space character.
    Last edited by Haluk; 02-21-2022 at 06:35 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Extract substring from cell
    By dluhut in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 11-06-2019, 01:17 PM
  2. Extract substring if condition is met
    By heyJefe in forum Excel General
    Replies: 1
    Last Post: 08-30-2016, 08:38 PM
  3. [SOLVED] Extract a substring with find and mid
    By AlexRoberts in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 08-08-2013, 04:02 AM
  4. extract part of string with multiple separators
    By orimpila in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-28-2013, 07:24 AM
  5. [SOLVED] Extract Substring, then Ignore that Substring, while collecting data from Other substrings
    By Sameki121 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-17-2012, 05:21 PM
  6. Extract a substring with formula
    By bobwachs in forum Excel General
    Replies: 2
    Last Post: 09-10-2010, 04:47 PM
  7. Extract 1st matching substring from cell
    By mtgiles in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 11-26-2008, 03:34 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1