2

I'm cleaning up files using Notepad ++, and trying to delete lines that start with \pard and have some text then end with a line feed. But \n doesn't work in RegEx and .* doesn't work in an extended find and replace.

This is what I've tried unsuccessfully: \pard.*\n

\pard.* works but leaves the line feed in RegEx.

Nimantha
  • 6,405
  • 6
  • 28
  • 69
Sarah
  • 21
  • 1
  • 1
  • 3
  • I think [this answer](http://stackoverflow.com/questions/918158/how-to-delete-specific-lines-on-notepad/918225#918225) to a closely related question will do what you need. – Cameron Oct 24 '10 at 18:26
  • Yeah, I think Cameron's suggestion is the best you're going to do--with Notepad++, at least. I recommend you get an editor with *real* regex support, like EditPad Pro. http://www.editpadpro.com/ – Alan Moore Nov 15 '10 at 06:10
  • To anyone of the future: You could also try https://stackoverflow.com/a/918225 and put off learning regex for some more time (but it will inevitably have to happen some day, I trust). – thymaro Jan 06 '18 at 19:55

2 Answers2

2
\\pard.*(\r)?\n

The question mark after the repeater is so that it isn't greedy or it will swallow most of the file including the parts it shouldn't...

Editted: Now it should handle line breaks properly

Edit: Try this

^\\pard.*$
J V
  • 11,402
  • 10
  • 52
  • 72
  • 1
    Notepad++ does not recognize greedy/ungreedy modifiers. – BoltClock Nov 14 '10 at 18:50
  • The problem isn't the carriage return, it's Notepad++ itself. NPP's "Regular Expression" search mode works on one line at a time--it actually strips off the line separators before applying the regex. And its "Extended" mode supports several kinds of escapes including `\n`, `\r`, etc., but has none of the other features associated with regexes (or even globs). There's no way to combine the two modes; as the OP said, you can have line separators or regexes, but not both. – Alan Moore Nov 15 '10 at 05:55
  • No I know theres a way, I used to use it all the time (Before I switched to linux) Try the new one... – J V Nov 15 '10 at 09:27
  • Nope! `^\\pard.*$` works in NPP like like it does in any other flavor: it finds the correct line, but the match doesn't include the line separators (leading *or* trailing). Maybe you're thinking of the "Find All/Delete Bookmarked Lines" trick from that other thread Cameron linked to. Or a plugin. – Alan Moore Nov 15 '10 at 11:28
  • Thanks for all the interest, unfortunately I had to complete the task somewhat manually and no longer have the files to trial your suggestions. Thanks again. – Sarah Nov 15 '10 at 11:59
  • Perhaps replace would work if you used "select all" first, either way, npp seems to be a pita, I'd just open it in something more robust. – J V Nov 15 '10 at 12:59
0

do you mean exactly "\pard" or "\p"ard? If it's the first then you need to escape the "\" with another "\".

\\pard.*\n

You may also need to look at the new line character actually being a pc format which is \r\n

\\pard.*\r\n
Keng
  • 52,011
  • 32
  • 81
  • 111