How to replace everything with blank after question mark in a string?

Simply use JavaScript function

var str = "/root/Users?SkillId=201;";
var str = str.substring( 0, str.indexOf("?")-1 );
console.log(str);

here is the fiddle: https://jsfiddle.net/ahmednawazbutt/2fatxLfe/3/


Match the content before ?

var str = "/root/Users?SkillId=201;"
var a = str.match(/(.*)\?/);

console.log(a[1])

Another option is to get the substring before the '?':

str = str.substr(0, str.indexOf('?'));


This should help

var str = "/root/Users?SkillId=201;"

str = str.replace(/\?.*$/g,"");
console.log(str);

Tags:

Javascript