nlp-pattern-match
nlp-pattern-match copied to clipboard
match-test-replace: modify match range
Currently, first match range is final range. We want to change the range at runtime.
diff --git a/packages/match-test-replace/src/match-test-replace.ts b/packages/match-test-replace/src/match-test-replace.ts
index 0347700..10ca9a8 100644
--- a/packages/match-test-replace/src/match-test-replace.ts
+++ b/packages/match-test-replace/src/match-test-replace.ts
@@ -15,6 +15,8 @@ export interface TestMatchReplaceReturnDict {
// match pattern
// if the result of match `pattern` is falsy, return { ok: false }
pattern: RegExp;
+ // sub match range
+ match?: (args: PatternMatchDictArgs) => RegExp;
// test the result of match
// if the result of `test` is true, allow to replace if needed
test?: (args: PatternMatchDictArgs) => boolean;
@@ -130,6 +132,10 @@ export const matchTestReplace = (text: string, dict: TestMatchReplaceReturnDict)
captures,
all
};
+ if(typeof dict.match === "function"){
+ dict.match(dictArgs);
+ // re replace and test
+ }
if (typeof dict.test === "function") {
isReplaceOK = dict.test(dictArgs);
}