javascript - Regular expression to remove more than one continuous "--" -


i have 2 requirements, first, want replace "-" symbol in both beginning , end of text empty value. second, if there continuous "-" symbols should replaced single "-" symbol.

if possible please provide code both requirements in single pattern.

code:

//1.) // replace more 1 "-" in b // expected output : -asdas-sadf-asdasd-ju  var = "--asdas-sadf----asdasd---ju"; = a.replace(/-{2,}/,""); //alert(a);  //2.) // remove last "-" , starting "-" b "das-" - after das needs removed // expected output : welcome/asasdgrd/asd-ast-yret-das/456  var b = "-welcome/asasdgrd/asd-ast-yret-das-/456" b = b.replace(/[-$]/,""); //alert(b); 

fiddler link:

http://jsfiddle.net/nj5j0yeq/1/

you need use capturing groups.

var s = "--asdas-sadf----asdasd---ju";  alert(s.replace(/^-+|-+$|(-)+/gm, "$1"));


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -