diff --git a/lib/Builder.js b/lib/Builder.js index 96398ad..2528895 100644 --- a/lib/Builder.js +++ b/lib/Builder.js @@ -704,6 +704,7 @@ class Builder { clone._modifiers = this._modifiers clone._lastMethodType = this._lastMethodType clone._group = this._group + clone._captureNames = Array.from(this._captureNames) return clone } diff --git a/test/builder-test.js b/test/builder-test.js index dbfb3ed..7f41007 100644 --- a/test/builder-test.js +++ b/test/builder-test.js @@ -178,4 +178,32 @@ describe('Builder isMatching', () => { assert.deepEqual(regex, /(?:foo)/) }) + + it('Stores named captures', () => { + const regex_new = new SRL("capture (anything once or more) as first"); + const testcase = 'hello world'; + + let matches_new = regex_new.getMatch(testcase) + assert.equal(matches_new["first"], 'hello world') + + const regex_cached = new SRL("capture (anything once or more) as first"); + + let matches_cached = regex_cached.getMatch(testcase) + assert.equal(matches_cached["first"], 'hello world') + + }) + it('Stores named captures with implodeString', () => { + const query = "begin with literally 'hello '\ncapture (anything once or more) as first"; + const regex_new = new SRL(query); + const testcase = 'hello world'; + + let matches_new = regex_new.getMatch(testcase) + assert.equal(matches_new["first"], 'world') + + const regex_cached = new SRL(query); + + let matches_cached = regex_cached.getMatch(testcase) + assert.equal(matches_cached["first"], 'world') + + }) })