Remove the unwanted vertical bar at the end of the string JS : <p>I have quite a similar input to output code scenario as this one:
<a href="http://plnkr.co/edit/eBjenGqgo3nbnmQ7XxF1?p=preview" rel="nofollow noreferrer">http://plnkr.co/edit/eBjenGqgo3nbnmQ7XxF1?p=preview</a></p>

<p>I am using AngularJS 1.5.7. Ng directives that my input - ( first ) textarea uses are the same as those shown in Plunkr (ng-list, ng-trim...). My output, unlike the Plunkr example, is displayed inside a ( second ) textarea, but logic is quite similar. $scope.outputValue is an output array which I am converting to string, and implementing 1 RegExp afterwards:  </p>

<pre><code>$scope.outputValue  =  $scope.outputValue.toString();
$scope.outputValue  =  $scope.outputValue.replace(/,/g, " | ");
</code></pre>

<p>Problem is that the generated string always adds an extra " | " at the end of itself. Often times an output looks like this if the user passes a couple of empty array items inside a first textarea:</p>

<pre><code>var foo = "one | two | three | four | | | | |";
</code></pre>

<p>But what I really need to display is this:</p>

<pre><code>var foo = "one | two | three | four";
</code></pre>

<p>The only thing that is important is to remove all the "|" that get attached to the end of the string as a replacement of ',' but the output can have "|" values as well, therefore:</p>

<pre><code>var foo = "one| | ||two| | three| | four||";
</code></pre>

<p>would also be a valid output.</p>

<p>Similar thing happens with Plunkr example, as it generates empty array items and separated by commas.  </p>

<p>Is there any RegExp that might be useful for this problem?</p>

<p>Thanks, Nenad</p>
