
Untitled
By: a guest on
May 4th, 2012 | syntax:
None | size: 0.86 KB | hits: 17 | expires: Never
RegEx: Compare two strings to find Alliteration and Assonance
text = ''
+'nAs I looked to the east right into the sun,'
+'nI saw a tower on a toft worthily built;'
+'nA deep dale beneath a dungeon therein,'
+'nWith deep ditches and dark and dreadful of sight'
+'nA fair field full of folk found I in between,'
+'nOf all manner of men the rich and the poor,'
+'nWorking and wandering as the world asketh.'
skipWords = ['the', 'and']
curr = []
text.toLowerCase().replace(/bw{3,}b/g, function(word) {
if (skipWords.indexOf(word) >= 0)
return;
var len = curr.length
if (!len || curr[len - 1].charAt(0) == word.charAt(0))
curr.push(word)
else {
if (len > 2)
console.log(curr)
curr = [word]
}
})
["deep", "ditches", "dark", "dreadful"]
["fair", "field", "full", "folk", "found"]
["working", "wandering", "world"]