Jeff Hertz
Jeff Hertz

Reputation: 31

notepad++ regex find and create new line below with specific text (while retaining the found line)

The issue I have is with g-code text. Need to find the line with "F150" the z lines are diffenrt values but needs to retain it, then add a line below G1 F1000. I tried regular expression

Find: (F150*)
Replace: \1\r\G1 F1000

and a few others to no avail.

G1 X277.8072 Y212.6482 Z-2.5000
G1 X277.3935 Y212.6617 Z-2.5000
G1 X276.9809 Y212.6737 Z-2.5000
G1 F150 Z-4.0000
G1 X276.9809 Y212.6738 Z-4.0000
G1 X276.5705 Y212.6846 Z-4.0000 

So end result becomes this:

G1 X277.8072 Y212.6482 Z-2.5000
G1 X277.3935 Y212.6617 Z-2.5000
G1 X276.9809 Y212.6737 Z-2.5000
G1 F150 Z-4.0000
G1 F1000
G1 X276.9809 Y212.6738 Z-4.0000
G1 X276.5705 Y212.6846 Z-4.0000 

Upvotes: 3

Views: 765

Answers (1)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 626845

You can use

Find What: \bF150\b.*
Replace With: $0\nG1 F1000

Details:

  • \bF150\b.* - a word boundary (\b), then a F150 substring, a word boundary, and then the rest of the line (till but not including any line break chars)
  • $0\nG1 F1000 - the whole match value ($0), a newline, and a G1 F1000 substring.

See the regex demo.

If you want to detect F150 inside a longer word, as in GDF1505, remove \b.

Upvotes: 3

Related Questions