0

I have an txt file with 65K lines. and not all are correct aligned.

So I need to replace the lines not ending with ;Yes or ;No with an space

Tried

^{^;Yes|^;No}$
revo
  • 47,783
  • 14
  • 74
  • 117
osomanden
  • 599
  • 1
  • 10
  • 26
  • 1
    Your question is incomplete. `regex` is not a tool but a language; it doesn't do anything by itself, you use it through a program. How do you attempt to replace the lines, what program do you use? The `regex` is syntactically incorrect, nevertheless. – axiac Apr 02 '18 at 08:46
  • oh correct.. I am using it in text editor to replace the end of lines – osomanden Apr 02 '18 at 08:47
  • 1
    *"text editor"* doesn't make the question more clear. There are dozens of text editors and they use different flavours of `regex`. Which text editor? – axiac Apr 02 '18 at 08:49
  • I am using UltraEdit – osomanden Apr 02 '18 at 08:51
  • This sounds like "*how do I use UltraEdit*", not a programming question. – melpomene Apr 02 '18 at 08:53
  • It could be. But I am asking for the regular expression.. – osomanden Apr 02 '18 at 08:54
  • There's no such thing as "*the* regular expression". Every tool has its own regex implementation with its own syntax and quirks. – melpomene Apr 02 '18 at 08:55
  • "*I am asking for the regular expression*" - Have you considered hiring a programmer? SO is not a "*write this code for me*" site. – melpomene Apr 02 '18 at 08:56
  • @melpomene You have your orders. Now start writing! :P – Tim Biegeleisen Apr 02 '18 at 08:58
  • 1
    Seems I have learned my lesson in being much more specific in my questions ;) Thank you for your assistance @revo. – osomanden Apr 02 '18 at 09:05

2 Answers2

2

Select Perl while enabling Regular Expressions. Put this in Find What:

(?m)^.*$(?<!;Yes|;No)

Put a space character in Replace with input field.

Breakdown:

  • (?m) Enable multline flag
  • ^.*$ Match a whole line
  • (?<! Start of a negative lookbehind
    • ;Yes Last 4 characters shouldn't be ;Yes
    • | Or
    • ;No ;No
  • ) End of negative lookbehind

Live demo

revo
  • 47,783
  • 14
  • 74
  • 117
  • I'm pretty sure actual Perl would require `$(?<!;Yes)(?<!;No)` there, but it's probably PCRE. :-) – melpomene Apr 02 '18 at 09:02
  • 1
    You're right. But mostly when they say Perl, they mean PCRE. This is documentation page where any one can refer to https://www.ultraedit.com/support/tutorials-power-tips/ultraedit/perl-regular-expressions-digging-deeper.html – revo Apr 02 '18 at 09:07
  • 1
    I didn't know it was possible to put a lookbehind _after_ the end marker `$`. Nice way to make the lookbehind as efficient as possible +1. – Tim Biegeleisen Apr 02 '18 at 09:21
0

Try the following find and replace in regex mode:

Find:

^(?!.*(Yes|No);$).*$

Replace:

(space)

Demo

This answer assumes that UltraEdit supports lookarounds. If not, then it won't work, and we would need an alternative approach.

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360