0

I have a long list of defined cities which I use in various projects.

I need to integrate it into a regex. Why does this not work?

var text = "It's nice in Amsterdam";

var cities = "(Berlin|Athens|Amsterdam|Buenos Aires|endless|list|from|extra|file)";
var cityRx = new RegExp("/.+ " + cities + "$/", "i");
var city = text.match( cityRx );

$("body").append( "Where ist nice? " +  city + "!" );

http://jsfiddle.net/hmvL9h08/

Martin
  • 2,007
  • 6
  • 28
  • 44

0 Answers0