I have come across a situation similar to the one demonstrated in this code snippet: http://plnkr.co/edit/eBjenGqgo3nbnmQ7XxF1?p=preview
Currently, I am working with AngularJS 1.5.7. The directives used in my input - ( first ) textarea are the same as those shown in the Plunkr example (ng-list, ng-trim...). However, my output is displayed within a different ( second ) textarea, but the underlying logic remains quite similar. $scope.outputValue represents an array that I am converting to a string and then applying a RegExp pattern to:
$scope.outputValue = $scope.outputValue.toString();
$scope.outputValue = $scope.outputValue.replace(/,/g, " | ");
The issue I am facing is that the resulting string consistently adds an additional " | " at the end. Oftentimes, the output appears like this when a user enters multiple empty array items in the first textarea:
var foo = "one | two | three | four | | | | |";
However, what I really want to display is:
var foo = "one | two | three | four";
The primary objective here is to eliminate all the "|" characters that are appended to the end of the string as replacements for ','. Nonetheless, it should be noted that the output may contain "|" values as well. Therefore, an output like this would also be valid:
var foo = "one| | ||two| | three| | four||";
A similar issue can be observed in the Plunkr example, where empty array items are generated and separated by commas.
Is there a RegExp solution that could help address this problem?