Finding expression between two words

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • raknin
    New Member
    • Oct 2007
    • 82

    Finding expression between two words

    Hi,

    I want to find a string as part of a long expression. I am using regexp match but with no success,

    Actually I am trying to find what is in between <embed> and </embed>
    can any one help me with this one. The code attached below


    Code is attached below:

    Code:
    <html>
    
    <head>
    
    <title></title>
    <script language="javascript" type="text/javascript">
        function validateFlashMoview() 
        {
      
        var flashString='<object width="425" height="355"><param name="movie" value="http://www.youtube.com/v/ItXDJy1JHvE&hl=en"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/ItXDJy1JHvE&hl=en" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"></embed></object>';
            var flashArray=flashString.match(/(embed*)+(*embed)/gi);
         
           for (i=0;i<flashArray.length;i++) 
           {
             alert(flashArray[i]);
           }
         //document.getElementById('flashMovie').innerHTML="'"+flashString+"'";
        }
    
    </script>
    </head>
    
    <body>
    
    
    <div id="flashMovie"></div>
    <input name="test" id="test" type="button" value="test" onclick="validateFlashMoview()">
    <br>
    
    </body>
    
    </html>
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    If you're trying to get the attributes of the embed tag in an array, just split on whitespace using the split() method. Alternatively, add the elements to the page, get the embed tag and just access them directly using:
    [code=javascript]var embed = document.getEle mentsByTagName( "embed")[0];
    var src = embed.src; // ... and so on[/code]

    Comment

    • raknin
      New Member
      • Oct 2007
      • 82

      #3
      Originally posted by acoder
      If you're trying to get the attributes of the embed tag in an array, just split on whitespace using the split() method. Alternatively, add the elements to the page, get the embed tag and just access them directly using:
      [code=javascript]var embed = document.getEle mentsByTagName( "embed")[0];
      var src = embed.src; // ... and so on[/code]
      Thanks Acoder,

      The issue is that I want to find out what is between the two embed open and close tag if exist using the regexp, I want to do it in one shot.


      How this line should be written?
      Code:
      var flashArray=flashString.match(/(embed*)+(*embed)/gi);
      Last edited by raknin; May 27 '08, 12:07 PM. Reason: missing information

      Comment

      • hsriat
        Recognized Expert Top Contributor
        • Jan 2008
        • 1653

        #4
        Didn't you try innerHTML?
        [code=javascript]var txt = document.getEle mentsByTagName( 'embed')[0].innerHTML;[/code]

        Comment

        • acoder
          Recognized Expert MVP
          • Nov 2006
          • 16032

          #5
          Originally posted by hsriat
          Didn't you try innerHTML?
          [code=javascript]var txt = document.getEle mentsByTagName( 'embed')[0].innerHTML;[/code]
          That wouldn't work unless the elements have been added to the page.

          @raknin, any reason why you must do this via a string and not have it added to the page first?

          Comment

          • Logician
            New Member
            • Feb 2007
            • 210

            #6
            Originally posted by raknin
            Hi,

            I want to find a string as part of a long expression. I am using regexp match but with no success,

            Actually I am trying to find what is in between <embed> and </embed>
            can any one help me with this one.
            Something like:
            Code:
            var content = str.match( /<embed.*>(.*)<\/embed>/i )[1] || "";

            Comment

            • raknin
              New Member
              • Oct 2007
              • 82

              #7
              Originally posted by Logician
              Something like:
              Code:
              var content = str.match( /<embed.*>(.*)<\/embed>/i )[1] || "";
              Thanks, thata what I was looking for

              Comment

              Working...