Link to home
Start Free TrialLog in
Avatar of MJ
MJFlag for United States of America

asked on

Append String to Page Name when Extension Isn't Necessarily Mandatory?

What  I want to do is append "-confirmation" to the URL of a page (but using output as a string). It will always be before the file extension, if one exists? Since the extension isn't mandatory, the URL can have two different structures. Not sure how to accomplish this?

 Example (==> means returns):

https://www.abc.com/dir1/dir2/lead-form.html    ==> https://www.abc.com/dir1/dir2/lead-form-confirmation.html
https://www.abc.com/dir1/dir2/lead-form    ==> https://www.abc.com/dir1/dir2/lead-form-confirmation
https://tech.internal.abc.com/dir1/webpage.html    ==> https://tech.internal.abc.com/dir1/webpage-confirmation.html
https://tech.internal.abc.com/dir1/webpage   ==> https://tech.internal.abc.com/dir1/webpage-confirmation

Any ideas?

Thanks!
Avatar of Leonidas Dosas
Leonidas Dosas
Flag of Greece image

function returnHtmlstr(arg){ 
  var string = arg,
    expr = /.html/; 
  if(string.search(expr)){
    string=string.replace('.html','');
    string=string+'-confirmation.html';
    string=string.replace(' ','');
    return string;
  }
}

console.log(returnHtmlstr('https://tech.internal.abc.com/dir1/webpage.html'));

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Pawan Kumar
Pawan Kumar
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial