We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hey there,
is there a particular reason for using nested .replace() calls instead of using the capture group directly?
.replace()
const text = 'due.b[0][0][0]'; const original = text.replace(/(\[.*\])/g, (str) => { return str .replace(/\[/g, '.') .replace(/\]/g, ''); }); const optimized = text.replace(/\[([^\]]+)\]/g, (match, token) => '.' + token); console.log(text); console.log(original); console.log(optimized);
The text was updated successfully, but these errors were encountered:
You could try to run the unit tests - one of the cases breaks here. I'm quite sure with some work it could be optimized though.
Sorry, something went wrong.
I see. This is happenning because you seem to allow nesting [due][a[0]]. In that case you can still remove the outer replacement and go with
[due][a[0]]
path .replace(/\[/g, '.') .replace(/\]/g, '') .replace(/^\./, '') .split('.')
Anyway, my question "if there was a reason to…" is answered :)
Thanks, for that one - will do a new build with a mention to you github alias :)
No branches or pull requests
Hey there,
is there a particular reason for using nested
.replace()
calls instead of using the capture group directly?The text was updated successfully, but these errors were encountered: