Regular Expressions 101

Community Patterns

Find line and insert under it

1

Regular Expression
Python

r"
(^[\t\s]*)(forgot: "to",)(?!\n[\t\s]*insert: "something",)
"
m

Description

Finds a line and appends the replacement below it. Tries to preserve indentation (tabs or spaces) and to avoid duplicate replacements.

I used it in Sublime Text to batch edit several instances of a JS config object across several files.

Submitted by anonymous - 8 years ago