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!
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
if class always follows name...
(in my example, the text above is in A1... adjust to suit your worksheet.)


<style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px 'Lucida Grande'}span.s1 {color: #006107}span.s2 {color: #ab30d6}span.s3 {color: #a54a29}span.s4 {color: #0057d6}span.s5 {color: #33af4a}</style>=TRIM(MID(SUBSTITUTE(SUBSTITUTE(A1,"name=""",REPT(" ", 1000)), """ class=", REPT(" ", 1000)),1000, 1000))
 
Upvote 0
Thank you!

Unfortunately, class does not always follow name. In fact, sometimes only one of those items will be present. Here are two different extracts -
HTML:
    <input id="q" aria-hidden="true" autocomplete="off" name="q" tabindex="-1" type="url" jsaction="mousedown:ntp.fkbxclk" style="opacity: 0;">

    <input value="Google Search" aria-label="Google Search" name="btnK" type="submit" jsaction="sf.chk">
 
Last edited by a moderator:
Upvote 0
Does this work for you?

=LEFT(MID(A1,SEARCH("name=""",A1,1)+6,999),SEARCH("""",MID(A1,SEARCH("name=""",A1,1)+6,999),1)-1)

Regards

Murray
 
Upvote 0
or this

<style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px 'Lucida Grande'}span.s1 {color: #006107}span.s2 {color: #ab30d6}span.s3 {color: #a54a29}span.s4 {color: #33af4a}span.s5 {color: #0057d6}span.s6 {color: #ff9c1b}span.s7 {color: #fe4fdd}</style>=TRIM(MID(SUBSTITUTE(REPLACE(REPLACE(A1,FIND("""", A1, FIND("name=""", A1)+6), 1, "§"),FIND("name=", A1), 6, "§"), "§", REPT(" ", 1000)), 1000,1000))
 
Upvote 0
Or this...

=LEFT(REPLACE(A1,1,SEARCH("name=",A1)+5,""),SEARCH("""",REPLACE(A1,1,SEARCH("name=",A1)+5,""))-1)
 
Upvote 0
Hello again! Would you help me to understand how to modify this? Your code works amazingly well, however I realized I sometimes have a need to grab innerhtml such as the following:
<span class="yt-uix-button-content">Search</span>

The only thing I can count on are > and < as all the rest will change. I'm struggling to understand how to obtain this... thank you for any help you can offer and I'll pass it along on these forums!
 
Upvote 0
It removed the code again... let's see if this works. The text I'm trying to cut out is inside this >textIwanttocutout<
 
Upvote 0

Forum statistics

Threads
1,213,532
Messages
6,114,177
Members
448,554
Latest member
Gleisner2

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