I am using AJAX to grab the contents of a webpage and I want to grab all instances of a sting pattern and put them into an array. The data I am extracting is in Sharepoint. I want all values that are between "-->" and " ". I already have the entire data chunk in a variable called "content". Can anyone help with a regexp to achieve this? Thanks
<script type="text/javascript"> function extractFromString(str, rxp, index) { var set = [], result; while( result = rxp.exec( str ) ) set.push( result[index] ); return set; } var data = "--> balls xxxx --- ==== --> are never shaped --> round ! " ; alert( extractFromString( data, /-->(.+?) /g, 1 ) ); </script> Code (markup):
Try this, var data = "--> balls xxxx --- ==== --> are never shaped --> round ! " ; var myArray = data.split(/-->| /); Tested here, displays as a space. http://www.pagecolumn.com/tool/regtest.htm