user7814645
user7814645

Reputation: 139

I'm try to use toLowerCase() along with .replace() method for a use case but having some difficulty

Let's say I have a website url named: https://clients.website.com/mock-client/matrix or https://clients.website.com/mock-client/Matrix

I'm trying to write some AngularJS code that will take the raw url as shown as an example above and remove the /matrix portion only. The thing is...is that it could be /matrix or /Matrix.

My current code looks like this:

var clientNetworkUrl = 
https://clients.website.com/mock-client/matrix
or
https://clients.website.com/mock-client/Matrix

vm.click = function() {
  var learnMoreUrl = clientNetworkUrl.replace('matrix', '');
  $window.open(learnMoreUrl, '_blank');
};

I would like the output of the function to always strip out /matrix whether it's capitalized or not. I tried lowercasing the whole url and read that might be a bad idea so I want to take a different approach.

Can anyone help me out with this?

Upvotes: 0

Views: 19

Answers (1)

charlietfl
charlietfl

Reputation: 171669

Just use a case sensitive regex

var urls =['https://clients.website.com/mock-client/matrix',
           'https://clients.website.com/mock-client/Matrix']

urls.forEach(str => console.log(str.replace(/matrix/gi,'')))

Upvotes: 1

Related Questions