I need a little help in trying to sanitize a string. I have written a regular expression that is pretty close to giving me the results I want but I just can't quite get it right. The string I'm receiving is in this format.
||a|assa||asss||ssss
The pipe character are basically placeholders to what would have been a separator for text. However, I'm trying to end up with something that would look like this.
|a|b|c|d in other words I'm just trying to remove consecutive pipes. I have put together a little example to illustrate what I have attempted and keep failing miserably.
const str1 = "||a||jump|fences||in the street";
const str2 = "im a wolf";
const hasPipe = /\|{1}\+/;//if the | is consecutevely repeated more than once than deleted.
console.log(hasPipe.test(str1));
console.log(str1.replace(hasPipe, ""))
console.log(hasPipe.test(str2));
The expected result to the above code should simply be.
|a|jump|fences|in the street"
Can someone please point me in the right direction or point my silly mistake.
+./\|\+/because that does not seem to work?+? Read the documentation and learn how regex works.