Fjott
Fjott

Reputation: 1137

Regex end of nth line

How can I use regex in sublime to target the end of every third line, so that I can insert a semicolon.

I know I can target/wrap every third line like this:

(.*\n){3}

And target the end of each line like this: $

But how can I target the END of every THIRD line so that I can insert a semicolon?

Upvotes: 0

Views: 603

Answers (1)

revo
revo

Reputation: 48711

You shouldn't match the third newline character. Try the following regex:

^.*(?:\R.*){2}\K

See live demo here

In above regex \R means any kind of newline character, \K means reset match output and ^ matches at start of each line by default in Sublime Text (so no need for (?m)).

Put the cursor at the beginning of file content then search for the given regex and replace with ;.

Upvotes: 3

Related Questions