diff --git a/doc/TwigJS.md b/doc/TwigJS.md
index 8d52d56e..9fb5d4ca 100644
--- a/doc/TwigJS.md
+++ b/doc/TwigJS.md
@@ -67,7 +67,7 @@ There are several extra functions defined for the TwigJS language:
 
 Extra filters:
 * filter websiteUrl: return a valid http link. Example: `{{ "www.google.com"|websiteUrl }}` -> "http://www.google.com"; `{{ "https://google.com"|websiteUrl }}` -> "https://google.com"
-* filter `matches`: regular expression match. e.g. `{{ "test"|matches("e(st)$") }}` returns `[ "est", "st" ]`. Returns null if it does not match.
+* filter `matches`: regular expression match. e.g. `{{ "test"|matches("e(st)$") }}` returns `[ "est", "st" ]`. You can pass a second parameter with [RegExp flags](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/RegExp). Returns null if it does not match.
 * filter `osmParseDate`: returns an array with the lower and upper boundary of the year of a `start_date` tag. See [openstreetmap-date-parser](https://github.com/plepe/openstreetmap-date-parser) for details.
 * filter `osmFormatDate`: returns the date as localized strings. Accept an object for options, e.g. `{{ tags.start_date|osmFormatDate({ format: 'short' }) }}`. See [openstreetmap-date-format](https://github.com/plepe/openstreetmap-date-format) for details.
 * filter `natsort`: Sort an array naturally, see [natsort](https://www.npmjs.com/package/natsort) for details.
diff --git a/src/twigFunctions.js b/src/twigFunctions.js
index 4326859a..d7e45024 100644
--- a/src/twigFunctions.js
+++ b/src/twigFunctions.js
@@ -53,7 +53,8 @@ OverpassLayer.twig.extendFilter('matches', function (value, param) {
     throw new Error("Filter 'matches' needs a parameter!")
   }
 
-  return value.toString().match(param[0])
+  const r = new RegExp(...param)
+  return value.toString().match(r)
 })
 OverpassLayer.twig.extendFilter('natsort', function (values, options) {
   return values.sort(natsort(options))