Link to home
Start Free TrialLog in
Avatar of hankknight
hankknightFlag for Canada

asked on

Finding instances of ##foobar##

Using JavaScript, I want var foobar to be the values in the body between ## and ##

For example:
How much  ##wood## does a woodchuck ##chuck## if a ##woodchuck## could chuck wood?

I want:
   foobar[0] = 'wood';
   foobar[1] = 'chuck';
   foobar[2] = 'woodchuck';

SOLUTION
Avatar of cy-wong
cy-wong

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of hankknight

ASKER

No, I want a script to FIND the values between ## and ##

Now your idea returns this:
How much does a woodchuck if a could chuck wood?

So I need JavaScript to find the values of foobar[1] from the body innerHTML
Avatar of HonorGod
Something like this perhaps?
<script type='text/javascript'>
  var text = 'How much  ##wood## does a woodchuck ##chuck## if a ##woodchuck## could chuck wood?'
  var info = text.split( '##' )
  var result = []
  for ( var i = 1; i < info.length; i += 2 ) {
    result[ result.length++ ] = info[ i ]
    doucment.write( info [i] + '<br>' )
  }
</script>

Open in new window

ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for the grade & points