With this expression, the entries of the array ‘strings’ are all of the formm “something+[up/down/left/right]”, except maybe the very last one. So for that last entry you have to check again:
N = strings.length;
all entries: strings[n] (n=0,…., N-2) have one of your direction patterns at the end;
the last entry (which is strings[0] if N===1) can be an exception:
if (strings[N-1].match(/\[(up|down|left|right)\]/)){
doThis; // direction spotted
}
else{
doThat; // no direction spotted
};
But… there is maybe another solution that leads more straigthforwardly to the same thing.
//===================
Edit: actually if you remove the (?!$) in the regexp (which tells not to match if the [up/down] pattern if right at the end of the string, i added this so you dont end up with an empty entry) then the last entry of string NEVER has a direction and all other have one:
strings = textIn.replace(/([(up|down|right|left)])s*/g, “$1″+D).split(D);
N = strings.length;
//>>> now all entries strings[n] (n=0,… N-2) have a direction, the last one not (and can be an empty string). Maybe better that way.