www.webdeveloper.com
Results 1 to 3 of 3

Thread: Find all occurences of a string inside of another string

Hybrid View

  1. #1
    Join Date
    Dec 2008
    Posts
    6

    Find all occurences of a string inside of another string

    Hello friends,

    I have made a blogpost here:

    How to find all occurences of a string in another string

    It is to find all occurences of a string inside another string.

    Please give your valuable suggestions.

  2. #2
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428

  3. #3
    Join Date
    Jun 2007
    Posts
    667
    Quote Originally Posted by vinodxx View Post
    It is to find all occurences of a string inside another string.

    Please give your valuable suggestions.
    Code:
    <script type='text/javascript'>
    
    String.prototype.getMatchIndices = function( find )
    {
     var indices = [], data, exp = ( typeof find == 'string' ? new RegExp(find, 'g') : find ) ;  
       
     while( ( data = exp.exec(this) ) )
      indices.push( data.index );
      
     return indices.length ? indices : null;   
    }
    
    
    alert( "positionofoccurrences".getMatchIndices(/o/g) );
    
    alert( "positionofoccurrences".getMatchIndices("curr") );
    
    alert( "positionofoccurrences".getMatchIndices("not") );
    
    </script>

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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