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

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -