Extract Text From Variable Length String

Marmit424

Board Regular
Joined
Jul 12, 2016
Messages
58
Hi!


I'm trying to extract text from variable strings. Here is a string example:


id="here_is_an_id" name="here_is_a_name" class="here_is_a_class"


I want to extract the text inside name"". However that text length changes, and the fact that it's not the only item in quotes confuses me on how to use the len,mid,search functions. Would someone please help me accomplish this? Thank you so much!
 
Assuming you there will only be one "href" tag per cell, you could use this formula to get the text you want...

=TRIM(REPLACE(LEFT(A1,FIND("<",A1,SEARCH("< a href=",A1)+9)-1),1,FIND(">",A1,SEARCH("< a href=",A1)+9),""))

Edit Note: You must remove the extra spaces after the two highlighted less than symbols.
Minor correction to the above formula... I believe it is possible for there to be Line Feed characters and/or Carriage Return characters within the "href" tag structure. I think this should eliminate them...

=SUBSTITUTE(SUBSTITUTE(TRIM(REPLACE(LEFT(A1,FIND("<",A1,SEARCH("< a href=",A1)+9)-1),1,FIND(">",A1,SEARCH("< a href=",A1)+9),"")),CHAR(10),""),CHAR(13),"")

Edit Note: You must remove the extra spaces after the two highlighted less than symbols.
 
Last edited:
Upvote 0

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Rick - see posts #25 and #26. :)
I may have read too much into the question that was asked. If the only thing in the cell is the "href" tag and nothing more, then I would think this formula should work as well...

=REPLACE(LEFT(A1,LEN(A1)-4),1,FIND(">",A1),"")
 
Upvote 0

Forum statistics

Threads
1,214,522
Messages
6,120,019
Members
448,938
Latest member
Aaliya13

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top