+ Reply to Thread
Results 1 to 10 of 10

How can I extract the nth instance of text between two strings?

  1. #1
    Registered User
    Join Date
    07-20-2019
    Location
    Cairns, Australia
    MS-Off Ver
    2016
    Posts
    3

    How can I extract the nth instance of text between two strings?

    Hi. I want to extract text between every instance of the html bullet point markers <li> and </li> so I can separate bullet points. I am thinking it's like the SUBSTITUTE function, since that can substitute between the the two strings in the nth instance. THanks!

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2503 (Windows 11 Home 24H2 64-bit)
    Posts
    90,309

    Re: How can I extract the nth instance of text between two strings?

    Welcome to the forum.

    Assuming the text is in A2, try this in B2 drag copied to the right:

    =TRIM(MID(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE($A2,"<li>","|"),"</li>","|"),"|",REPT(" ",LEN($A2))),(COLUMNS($A:A)-1)*LEN($A2)+1,LEN($A2)))
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

  3. #3
    Registered User
    Join Date
    07-20-2019
    Location
    Cairns, Australia
    MS-Off Ver
    2016
    Posts
    3

    Re: How can I extract the nth instance of text between two strings?

    Thanks, but all I got was the text before the first <li>. I know what dragged copied to the right means but I'm not sure how I am supposed to apply that. I just entered the formula into B2 to get the result I got.

  4. #4
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2503 (Windows 11 Home 24H2 64-bit)
    Posts
    90,309

    Re: How can I extract the nth instance of text between two strings?

    Please attach a sample workbook so we can take a look.

    Unfortunately the attachment icon doesn't work at the moment, so to attach an Excel file you have to do the following: just before posting, scroll down to Go Advanced and then scroll down to Manage Attachments. Now follow the instructions at the top of that screen.

  5. #5
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2503 (Windows 11 Home 24H2 64-bit)
    Posts
    90,309

    Re: How can I extract the nth instance of text between two strings?

    I just entered the formula into B2 to get the result I got.
    You enter it into B2, then you grab the little black box in the bottom right of the cell and drag it to the right to copy the formula to the other cells in the row.
    Attached Images Attached Images
    Last edited by AliGW; 07-21-2019 at 02:43 AM.

  6. #6
    Registered User
    Join Date
    07-20-2019
    Location
    Cairns, Australia
    MS-Off Ver
    2016
    Posts
    3

    Re: How can I extract the nth instance of text between two strings?

    I uploaded a file. It works but the correct info is in the 2nd, 4th, 6th column dragged across to. If you don't want to fix it I can work with it anyway
    Attached Files Attached Files

  7. #7
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2503 (Windows 11 Home 24H2 64-bit)
    Posts
    90,309

    Re: How can I extract the nth instance of text between two strings?

    Why would I NOT want to fix it? This is a HELP forum!

    Let me take a look ...

  8. #8
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2503 (Windows 11 Home 24H2 64-bit)
    Posts
    90,309

    Re: How can I extract the nth instance of text between two strings?

    Try this modified version:

    =TRIM(MID(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE($A2,"<li>","|"),"</li>","|"),"||","|"),"|",REPT(" ",LEN($A2))),(COLUMNS($A:A)-1)*LEN($A2)+1,LEN($A2)))

  9. #9
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2503 (Windows 11 Home 24H2 64-bit)
    Posts
    90,309

    Re: How can I extract the nth instance of text between two strings?

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.

  10. #10
    Forum Guru
    Join Date
    02-27-2016
    Location
    Vietnam
    MS-Off Ver
    2024
    Posts
    6,174

    Re: How can I extract the nth instance of text between two strings?

    Just fix it a little.

    =TRIM(MID(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE($A2,"<li>","|"),"</li>","|"),"|",REPT(" ",LEN($A2))),(COLUMNS($A:A)*2-1)*LEN($A2)+1,LEN($A2)))

+ 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. [SOLVED] Extract text before the first instance of period or hyphen
    By gratedane8 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 06-20-2017, 10:31 AM
  2. [SOLVED] Trying to extract text cells at the first instance of four consecutive numbers
    By portokie in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 07-15-2016, 06:32 PM
  3. [SOLVED] Extract all text from right until first instance of symbol
    By Daedra in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 05-19-2015, 06:28 AM
  4. [SOLVED] Extract numbers before first instance of text
    By pauldaddyadams in forum Excel General
    Replies: 5
    Last Post: 08-12-2014, 07:34 AM
  5. Extract text strings
    By wazing in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 07-22-2010, 01:25 PM
  6. How to Extract Text Before Second Instance of a Symbol
    By lionsdeal in forum Excel General
    Replies: 2
    Last Post: 08-04-2009, 02:28 PM
  7. extract text strings
    By jhelliar in forum Excel General
    Replies: 5
    Last Post: 09-16-2008, 12:19 PM

Tags for this Thread

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