1

Hi I'm a newbie with javascript and I was wondering how do I strip all the text except the word TB_iframeContent800 . the digits at the end varies.

here is an example string

<iframe frameborder="0" style="width: 670px; height: 401px;" onload="tb_showIframe()" name="TB_iframeContent80" id="TB_iframeContent" src="http://www.gorgeoushentai.com/wp-admin/media-upload.php?post_id=33&amp;" hspace="0">This feature requires inline frames. You have iframes disabled or your browser does not support them.</iframe>

I want to extract TB_iframeContent80 and store it as a variable. So how can you do this using regex with javascript? please note the last 2 digits varies cause the number always changes so it sometimes become a 3 digit number.

4
  • 1
    are you trying to extract iframe name? Commented Oct 26, 2012 at 8:55
  • 5
    Please just use JavaScript's DOM manipulation and not regex. Commented Oct 26, 2012 at 8:55
  • yes I'm trying to extract the iframe name Commented Oct 26, 2012 at 8:56
  • Then using the DOM functionality would be semantically correct, and easier to achieve. Commented Oct 26, 2012 at 8:57

4 Answers 4

4
 var iframeName = document.getElementsByTagName("iframe")[0].name

if you've include jQuery then it could be something like this:

 var iframeName = $("iframe:first").attr("name");
Sign up to request clarification or add additional context in comments.

Comments

1

If jQuery is an option I think you are looking for something like this

$('iframe[name^="TB_iframeContent"]')

Comments

1

If you wont use DOM (because code analysis etc) just try this regex

var code = '<iframe ... /iframe>';

var result = code.match( /name="([^"]*)"/ );

var extract = result[1];

this selects the content of the name attribute

Comments

1

You could load html youre parsing like this and use DOM to get its name (its easier and more reliable way than using a regex):

var loadhtml = document.createElement('div');
loadhtml.innerHTML = 'yourHtml';

var theName = loadhtml.getElementsByTagName('iframe')[0].name;

If you use Jquery you could consider attr("name") as way to get name

However if you insist using a Regex here is one :

/< *iframe[^>]*name *= *['"]([^'"]*)/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.