Skip to content

Commit

Permalink
Use regex instead of sets to remove /g (#7785)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsoulanille authored Jul 11, 2023
1 parent 5c3f76e commit 206c0af
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions tfjs-layers/src/layers/nlp/match_all_polyfill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@
// TODO(mattSoulanille): Replace this with automatic polyfilling using core-js.
export function *matchAll(str: string, regexp: RegExp): IterableIterator<RegExpMatchArray> {
// 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;
Expand Down

0 comments on commit 206c0af

Please sign in to comment.