Skip to content

Sed should allow a replacement string to contain \1 for match groups #507

@nfischer

Description

@nfischer

Sed should accept replacement strings that contain \1 and \2 and the like, for the sake of doing replacements. Currently, this is probably supported by $1, $2, etc. (but that's JS-syntax, not Unix-syntax).

sed(/my(.*)regex$/, '\\1 works', 'file.txt');
// probably the closest we can get to Unix sed's syntax without a breaking change:
// sed 's/my.*regex$/\1 works/' file.txt

This ties in closely with shx sed, since it doesn't currently support substitutions like this.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions