Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 4th, 2012  |  syntax: None  |  size: 0.86 KB  |  hits: 17  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. RegEx: Compare two strings to find Alliteration and Assonance
  2. text = ''
  3. +'nAs I looked to the east right into the sun,'
  4. +'nI saw a tower on a toft worthily built;'
  5. +'nA deep dale beneath a dungeon therein,'
  6. +'nWith deep ditches and dark and dreadful of sight'
  7. +'nA fair field full of folk found I in between,'
  8. +'nOf all manner of men the rich and the poor,'
  9. +'nWorking and wandering as the world asketh.'
  10.  
  11. skipWords = ['the', 'and']
  12. curr = []
  13.  
  14. text.toLowerCase().replace(/bw{3,}b/g, function(word) {
  15.     if (skipWords.indexOf(word) >= 0)
  16.         return;
  17.     var len = curr.length
  18.     if (!len || curr[len - 1].charAt(0) == word.charAt(0))
  19.         curr.push(word)
  20.     else {
  21.         if (len > 2)
  22.             console.log(curr)
  23.         curr = [word]
  24.     }
  25. })
  26.        
  27. ["deep", "ditches", "dark", "dreadful"]
  28. ["fair", "field", "full", "folk", "found"]
  29. ["working", "wandering", "world"]