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 :(

0

2 Answers 2

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)

Sign up to request clarification or add additional context in comments.

Comments

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, ''));

2 Comments

What if football clup's name contains FC like OFFCAST ?
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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.