1

I have a list in this format

FIRSTTEXT:SECONDTEXT:RANDOMTEXT::::::::RANDOMNUMBERS:NUMBER:

but all the text is not in this format. i want to save only FIRSTTEXT:SECONDTEXT, firsttext and secondtext are in the same position on all document !

I have tried this one:

Find what: (.+):(.+)
Replace with: \1:\2

However, it doesn't work.

4
  • i want to clean all the other text except Firsttext:secondtext Commented Jan 12, 2020 at 22:20
  • .+ is greedy; Try .+?
    – smac89
    Commented Jan 12, 2020 at 22:21
  • 1
    Try ^(?:([^:\s]+:[^:\s]+).*|.*\R*), replace with $1 Commented Jan 12, 2020 at 22:25
  • Wiktor stribizew thank you works well Commented Jan 12, 2020 at 22:29

1 Answer 1

1

You may use

Find What: ^(?:([^:\s]+:[^:\s]+).*|.*\R*)
Replace With: $1

Details

  • ^ - start of a line
  • (?: - start of a non-capturing group:
    • ([^:\s]+:[^:\s]+) - Group 1 ($1 refers to this value):
      • [^:\s]+ - 1+ chars other than whitespace and :
      • : - a colon
      • [^:\s]+ - 1+ chars other than whitespace and :
    • .* - 0+ chars other than any line break char, as many as possible
  • | - or
    • .* - 0+ chars other than any line break char, as many as possible
    • \R* - 0+ line break sequences
  • ) - end of the non-capturing group.

Demo and settings:

enter image description here

Not the answer you're looking for? Browse other questions tagged or ask your own question.