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
  • 10,151
  • 22
  • 81
  • 143

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
  • 37,421
  • 4
  • 57
  • 85
  • 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)

Michael Mikhjian
  • 2,760
  • 4
  • 36
  • 51