What regular expression will take the message text and all tabs to a certain word, for example, to the word "Malibu"?

  • text and all tabs - why is it divided? Are tabs not text? - MihailPw
  • Isn't it easier to find the index of the occurrence of this word and take the whole line first to the found index? It will be faster and easier, besides the regulars for this task are not suitable. - Sergey
  • Well, I did it myself so far, but I wanted to understand how to make it a regular way. more reliable after all. - kot_mapku3
  • In this case - a bad idea. Not for this they. - Sergey
  • I fully agree with your phrase, obviously XY problem, but this is not the answer, but only a comment. - AK

1 answer 1

As the author wishes through the regulars (take the first match):

.+?(?=Малибу) 
  • Expression .+? - takes all characters ( . - all characters) to the first match ( +? - "lazy" selection);
  • The expression (?=...) is called Positive lookahead and takes a match by the expression ( .+? We have), which is before the expression inside ( Малибу in our case).

Test !

But, as @Sergey said, this path is far from optimal for such a trivial task.

  • How does it work?) First, anything, and then how does it stand for (two questions)? - kot_mapku3
  • @ kot_mapku3 updated the answer. - MihailPw