Open
Description
Hello!
Here is the test to reproduce the issue:
it("non-capturing groups should not capture with expression", () => {
const re = new RegExp("(?:^|\\s|-)\\S", "g");
const input = "hello, great-world";
let match = exec(re, input);
expect(match.matches.length).toBe(1);
expect(match.matches[0]).toBe("h");
match = exec(re, input);
expect(match.matches.length).toBe(1);
expect(match.matches[0]).toBe(" g"); // this fails and return the second letter (and each consecutive exec will return all the letters)
match = exec(re, input);
expect(match.matches.length).toBe(1);
expect(match.matches[0]).toBe("-w");
});
While in Javascript:
const re = new RegExp("(?:^|\\s|-)\\S", "g");
const input = "hello, great-world";
> re.exec(input);
[ 'h', index: 0, input: 'hello, great-world', groups: undefined ]
> re.exec(input);
[ ' g', index: 6, input: 'hello, great-world', groups: undefined ]
> re.exec(input);
[ '-w', index: 12, input: 'hello, great-world', groups: undefined ]
> re.exec(input);
null
Or on one line:
'hello, great-world'.replace(/(?:^|\s|-)\S/g, x => x.toUpperCase())
> 'Hello, Great-World'
Happy to give it a shot, if you have any hint where to start looking it would probably save me a lot of time :-)
Thanks!
Metadata
Metadata
Assignees
Labels
No labels