I want to achieve the following:
1) Check every word from a textarea if it is a guitar chord.
To do that, I created an array which contains all characters that guitar chords have (if a word matches the characters from this array it is a guitar chord):
var Regex = /^\s*(?:(A|B|C|D|E|F|G|A#|C#|D#|F#|G#|Ab|Bb|Db|Eb|Gb){1}(?:m|\+|\-|aug|dim|add|b|#|1|2|3|4|5|6|7|8|9|0|\/)*\s*)+$/;
2) If a word matches, I want it to become a link, pointing to an URL customized by the word itself.
e.g. The following line
Am Bb C# Dadd9
Song lyrics here
should turn into
<a href="example.com/Am">Am</a> <a href="example.com/Bb">Bb</a> <a href="example.com/C#">C#</a> <a href="example.com/Dadd9">Dadd9</a>
Song lyrics here
And here's what I've com up to for step 2:
var link = "http://www.example.com/";
$.each(chord, function(index, value) { //append link to chord
$('.output').append('<a href="' + link + value + '">' + value + '</a> ');
});
But I need to define "chord". How can I do to check each word, then if it is a chord (matching "Regex" characters) append link?