atom / find-and-replace

Find and replace in a single buffer and in the project
MIT License
242 stars 219 forks source link

Allow for $0 in regex find replace for the whole capture #1127

Open xbony2 opened 4 years ago

xbony2 commented 4 years ago

Summary

In find replace operations with regex on, $1 in the Replace field refers to the first capture group. In some programming languages/text editors, they will make $0 or the first index (result[0]) of the array returns the entire capture.

Motivation

This is useful when you want to paste the whole thing. Like consider if you have a list of phone numbers, and you use the regex "((\d{3}))(\d{3})-(\d{4})" to try to make it like "Number: ." To do this you kind of have to reconstruct it like "Number: ($1)$2-$3". Under this proposal you just do "Number: $0" which would be easier. This is a trivial example, I used it since I just used it, but you can imagine more complicated ones.

Describe alternatives you've considered

Reconstructing the match, but in some cases, this is inconvenient to do.

Additional context

Current:

image

Potential:

image