www.webdeveloper.com
Results 1 to 3 of 3

Thread: [RESOLVED] Search for a string and write condition

  1. #1
    Join Date
    Jun 2009
    Posts
    18

    resolved [RESOLVED] Search for a string and write condition

    Hi Guys!

    How to say:

    Find the string k= in the html source script[0] tag. Find the first ' after that. Extract the the string between them and check if it's 10 characters long. If it's 10 characters then do something...

    In the html source it's looking like k=xxxxxxxxxx'

    Thanks a lot!

  2. #2
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,670
    Code:
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="utf-8" />
    <title>123</title>
    <style></style>
    <script>
    /* just a sample script */
    var a,
        b,
    	c=true,
    	mystring='k=abcde12345',
    	falsestring1='K=abcde12345',
    	falsestring2='k=aabcde12345';
    function whatever(){return false;}
    </script>
    <script>
    function seek(haystack){
    var re=/k\=(.{10})+'/g,
        Result=re.exec(haystack);
    return Result[1] || false;
    }
    
    window.onload=function(){
    var str=seek(document.scripts[0].innerHTML);
    /* if(extracted string){do smth with it} */
    if(str){document.getElementById('result').innerHTML='found <b style="color:Crimson">'+str+'</b>';}
    }
    </script>
    </head>
    <body>
    <div id="result"></div>
    </body>
    </html>

  3. #3
    Join Date
    Oct 2010
    Location
    Versailles, France
    Posts
    1,270
    Something like this ?
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    <meta name="generator" content="PSPad editor, www.pspad.com">
    <title></title>
    <style type="text/css">
    body{margin:0;padding:0;font-family;georgia0}
    #pge{display:block;width:600px;margin:30px auto;}
    </style>
    <script type="text/javascript">
    window.onload=function(){
        var txt=document.body.innerHTML.replace(/<\/?[^>]+>/g,'');// the text without tags
        txt.replace(/=([^']{10,10})'/g,function(a,b){alert(b); /*do something with b */ });
    }
    </script>
    </head>
    <body>
    <div id="pge"><fieldset><legend>Find string</legend>
    <p>Lorem ipsum dolor sit amet consectetuer aliquet tincidunt molestie dui non. </p>
    <p>Nibh hendrerit tristique sit mi et odio=search me!'chose' boy augue lobortis ut elit. </p>
    <p>Justo condimentum dui non consectetuer nisl ac elit feugiat Aenean ipsum. </p>
    <p>Nibh nibh pede et magna=find this!'truc'  Vestibulum Vestibulum est laoreet non eleifend. Neque dolor urna.</p>
    <p>Nibh pharetra lobortis ac Nunc dui augue urna sapien Vestibulum In.</p>
    <p>Lacus Fusce pharetra Nunc iaculis laoreet lacinia id tellus Aenean eget.</p>
    <p>Sed *** Curabitur interdum vestibulum et tortor amet Nulla id ipsum.</p>
    </fieldset></div>
    </body>
    </html>
    To adapt with the nature of the body content...
    Last edited by 007Julien; 01-06-2014 at 10:25 AM. Reason: complement

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles