-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
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
prefer-lookaround
should ignore ^
and $
#478
Comments
Can confirm. This should be reported. In general, there may be any number of assertions after the capturing group to be replaced. The rule should do this: -'JavaScript'.replace(/Java(Script)$/g, 'Type$1')
+'JavaScript'.replace(/Java(?=Script$)/g, 'Type')
It's not, the assertion after the capturing group has to be placed at the end of the new lookahead. Example: > 'JavaScript'.replace(/Java(Script)$/g, 'Type$1')
'TypeScript'
> 'JavaScript'.replace(/Java(?=Script)$/g, 'Type')
'JavaScript'
> 'JavaScript'.replace(/Java(?=Script$)/g, 'Type')
'TypeScript' In fact, |
Thank you! You are right. |
So, to summarize var str = 'JavaScript'.replace(/Java(Script)$/g, 'Type$1')
// ->
var str = 'JavaScript'.replace(/Java(?=Script$)/g, 'Type') And var str = 'JavaScript'.replace(/Java(S)(c)(r)(i)(p)(t)/g, 'Type$1$2$3$4$5$6')
// ->
var str = 'JavaScript'.replace(/Java(S)(c)(r)(i)(p)(?=t)/g, 'Type$1$2$3$4$5')
// ->
var str = 'JavaScript'.replace(/Java(S)(c)(r)(i)(?=pt)/g, 'Type$1$2$3$4')
// ...
var str = 'JavaScript'.replace(/Java(?=Script)/g, 'Type') |
Information:
eslint-plugin-regexp
version: 7.31.10Description
The first two are reported, but the 3rd is not.
I think
should result the same. Will adding support for this case break things?
The text was updated successfully, but these errors were encountered: