Skip to content

Commit

Permalink
added TextUtils.replaceRuby()
Browse files Browse the repository at this point in the history
  • Loading branch information
yuko1101 committed Feb 4, 2024
1 parent 1363f88 commit 750630d
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/utils/text_utils.ts
Original file line number Diff line number Diff line change
@@ -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));
}
}

Expand Down

0 comments on commit 750630d

Please sign in to comment.