0

I'm trying to remove "FC", "AFC" or "London" if a string includes those strings. I have tried:

  $scope.teamName = function(url) {
            return url.replace('AFC'|'London'|'FC', '');
        }; 

String could be for example "Arsenal London FC".

Doesn't work though :(

user1937021
  • 9,133
  • 21
  • 75
  • 136

2 Answers2

1

You can use regex /AFC|London|FC/g to get all matches:

var str = "Arsenal London FC";
alert(str.replace(/AFC|London|FC/g, ''));
Shomz
  • 36,910
  • 3
  • 55
  • 83
  • What if football clup's name contains FC like OFFCAST ? – effe Feb 01 '15 at 19:56
  • It will fail just like the regular replace. :) OP said: `if a string includes those strings`, but that's why I left it case sensitive. – Shomz Feb 01 '15 at 19:58
1

It should be:

return url.replace(/AFC|London|FC/ig, "");

"i" = Case Insensitive

"g" = Global match (find all matches rather stopping after the first match)

MKN Web Solutions
  • 2,674
  • 3
  • 33
  • 49