0

I'm working with Multi Lang applications.

const kl_link = this.translator.instant('fbenrol.compliance_kl_link').replace('{{country}}', this.country).replace('{{language}}', this.language);

Above code will output the below result

'https://www.example.com/travel/nl_en//customer_support/privacy_policy/privacy_policy.htm '; 

Issue is,

I'm getting the // after the country language.

All these contents comes from the backend, Ideally it needs be fixed at the CMS side but since it is live issue, We need to come up quick fix.

How can this be done ? Please suggest.

I tried this, But it dosen't work.

kl_link.replace(/\/$/, '');
MasterX
  • 81
  • 2
  • 11

2 Answers2

2

Replace all the double slash by single slash. Try this-

const url = 'https://www.example.com/travel/nl_en//customer_support/privacy_policy/privacy_policy.htm';
const res = url.replace(/(?<!https:)\/\//g, '/');
console.log(res);
Sajeeb Ahamed
  • 6,070
  • 2
  • 21
  • 30
1

You can skip http patterns as many as you want

replace((!pattern_toskip)(pattern_to_replace/g,pattern)

const url = 'https://www.example.com/travel/nl_en//customer_support/privacy_policy/privacy_policy.htm';
const res = url.replace(/(?!https:\/\/)(?!http:\/\/)\/\//g, '/');
console.log(res);
Bala
  • 1,295
  • 1
  • 12
  • 23