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!
 
Unfortunately not, sometimes it will be < span > class="text" name="text" etc and then > textIwant < /span> and sometimes even that span will change.
It's HTML code, isn't it?

< span > is opening syntax
< / span > is closing syntax

Ergo the > to which you refer will be there.
What about the > in front of the "textIwant" that occurs between the < span> and the < /span>?
 
Last edited:
Upvote 0

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
I see how that created confusion. The item I want to extract is indeed prefaced by an a href tag, however that tag is not always the beginning of the HTML code. Ex:
< a href="javascript:EntityCrud.showAssetDetailView('APPLICATION',154871)" > Title Here < / a >
and
< a class="actionLinkLite" href="/genres/spirituality" > Spirituality < /a >

So it appears the item is always encased with that a just like you originally thought, my apologies!
 
Last edited:
Upvote 0
Try this:

=MID(A1,FIND(" > ",A1)+1,FIND(" < ",A1,2)-FIND(" > ",A1)-1)

Remove the spaces either side of the < and > once you have copied and pasted - they are there only to make the formula appear here.
 
Upvote 0
I see how that created confusion. The item I want to extract is indeed prefaced by an a href tag, however that tag is not always the beginning of the HTML code. Ex:
< a href="javascript:EntityCrud.showAssetDetailView('APPLICATION',154871)" > Title Here < / a >
and
< a class="actionLinkLite" href="/genres/spirituality" > Spirituality < /a >

So it appears the item is always encased with that a just like you originally thought, my apologies!
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.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,605
Messages
6,173,321
Members
452,510
Latest member
RCan29

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