REGEX - How can I select/mark 3 works delimited by tabs on a consecutive lines?

135 views Asked by At

Happy New Year !

I have a problem. I don’t know how to marks\select some words delimited by tabs on a consecutive lines: Recent, Coments and Tags

please see this print screen:

https://snag.gy/ZXNxJR.jpg

I can easy to put | sign, like: Recent|Comments|Tags but this will select all the words in the files that repeats, and I want only those 3 on those lines.

What I want is to make a regex, to remove all text before those 3 words, and another regex to remove everything after those 3 words.

I try something like this ((?s)((^.*)^.*Recente.*$|^.*Coments.*$|^.*Tags.*^))(.*$)but is not very good. And I have to pay atention, because those words can repeated in the text files, so I have to select\mark exactly those 3, on that 3 consecutive line (that doesn't have any other words on it)

2

There are 2 answers

3
Andreas On BEST ANSWER

Since you mentioned in a comment that you want to do this in Notepad++ (a fact that should have been mentioned in the question text), and since the screenshot shows a single space after the first two words, you might try this regular expression:

.*\n([ \t]+Recente\s+Coments\s+Tags).*

It will select everything, but capture the 3 words including whitespace between them and whitespace preceding first word on same line.

If you then replace with $1, everything not in the capture group will be removed.

enter image description here

Actually, the spaces after the first two words don't matter to this regex.

1
S.C On

Could you please try this in perl:

perl -0777 -ne 'while(m/((\s|\t)+)Recent\n\1Comments\n\1Tags/g){print "$&\n";}' /path/to/file

To breakdown:

  • Start with 1 or more tab characters (first capture group)
  • Then "Recent" followed by new line
  • Capture group, Comments and new line
  • Capture group, Tags

By the way, is "tab" really tab or multiple consecutive whitespaces (\s+)?