From 750630d0834f193d9f5c65dbbd3d0b3fae3bb52d Mon Sep 17 00:00:00 2001 From: yuko1101 <68993883+yuko1101@users.noreply.github.com> Date: Sun, 4 Feb 2024 16:10:58 +0900 Subject: [PATCH] added TextUtils.replaceRuby() --- src/utils/text_utils.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/utils/text_utils.ts b/src/utils/text_utils.ts index 8726ee8..c8f246e 100644 --- a/src/utils/text_utils.ts +++ b/src/utils/text_utils.ts @@ -1,6 +1,13 @@ class TextUtils { + + static readonly rubyRegex = /{RUBY_B#(.+?)}(.+?){RUBY_E#}/g; + static removeRuby(text: string): string { - return text.replace(/{RUBY_B#.+?}(.+?){RUBY_E#}/g, "$1"); + // same as this.replaceRuby(text, (match, base, ruby) => base); + return text.replace(this.rubyRegex, "$2"); + } + static replaceRuby(text: string, replacer: (match: string, base: string, ruby: string) => string): string { + return text.replace(this.rubyRegex, (match, base, ruby) => replacer(match, base, ruby)); } }