Skip to content

Files

Latest commit

 

History

History
18 lines (12 loc) · 416 Bytes

prefer-lookaround.md

File metadata and controls

18 lines (12 loc) · 416 Bytes

Pattern: Use of capturing group where lookaround would suffice

Issue: -

Description

This rule reports string replacement using capturing groups that can be replaced with lookaround assertions.

Examples

/* eslint regexp/prefer-lookaround: "error" */
/* ✓ GOOD */
var str = 'JavaScript'.replace(/Java(?=Script)/g, 'Type')

/* ✗ BAD */
var str = 'JavaScript'.replace(/Java(Script)/g, 'Type$1')