From 206c0af83966baadb64b8a3321fe71f3767237f5 Mon Sep 17 00:00:00 2001 From: Matthew Soulanille Date: Tue, 11 Jul 2023 13:22:04 -0700 Subject: [PATCH] Use regex instead of sets to remove /g (#7785) --- tfjs-layers/src/layers/nlp/match_all_polyfill.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tfjs-layers/src/layers/nlp/match_all_polyfill.ts b/tfjs-layers/src/layers/nlp/match_all_polyfill.ts index 7a4d21b8cec..81109f7187b 100644 --- a/tfjs-layers/src/layers/nlp/match_all_polyfill.ts +++ b/tfjs-layers/src/layers/nlp/match_all_polyfill.ts @@ -18,9 +18,8 @@ // TODO(mattSoulanille): Replace this with automatic polyfilling using core-js. export function *matchAll(str: string, regexp: RegExp): IterableIterator { // Remove the global flag since str.match does not work with it. - const flags = new Set(regexp.flags.split('')); - flags.delete('g'); - regexp = new RegExp(regexp, [...flags].join('')); + const flags = regexp.flags.replace(/g/g, ''); + regexp = new RegExp(regexp, flags); let match = str.match(regexp); let offset = 0;