REGEX again: How can I select/mark this 3 works on a different lines
-
I copy the last text, and this REGEX works, and it selects the first line. So this is good.
But, this will select only the first line. I need to select, practically, those 3 words, on a different line (3 line close one by another). And every word is not at the begginig of the line, but somewhere in the middle of the line, because of the tab.
In a big way, I want to make a regex, starting at those 3 words, and to remove everything after them and another regex to delete everything before them. The problem is that those 3 words are on different consecutive lines (line 13,14 and 15). Practically a group. I don’t want to select other the same words on the files, only those group, because I will use FIND/REPLACE ALL, so I don’t want to replace anything else.
I have the regex to remove everything after/before a word or words on a single line. But now I have to select a group of words on a different consecutive line, and to delete everything after/before them
-
and, please excuse me for the title. It had to be “How can I select/mark 3 words on 3 consecutive lines”. And each of the words are somewhere in the middle of lines, by tab or space.
-
Vasile,
I did understand that you wanted to mark the three consecutive lines of each block of lines, and not only the first one !
But, just follow my first post , on that topic :
To verify, copy, as before, my previous text in a new tab
- FIRSTLY, perform the S/R, below :
SEARCH
^\h*Recente\R(?=\h*Coments\R\h*Tags|\h*Tags\R\h*Coments)|^\h*Coments\R(?=\h*Recente\R\h*Tags|\h*Tags\R\h*Recente)|^\h*Tags\R(?=\h*Recente\R\h*Coments|\h*Coments\R\h*Recente)
REPLACE
#$0
=> A sharp character,
#
, should be inserted at the beginning of the FIRST line of each block
- SECONDLY, perform the three regexes , below, ONE AFTER ANOTHER, in the Mark dialog, by clicking on the Mark All button
SEARCH
(?-s)^#.+
SEARCH
(?-s)^#.+\R\K.+
SEARCH
(?-s)^#(.+\R){2}\K.+
=> At the end, each line, of each block, should be marked
But, from what you said in your last post, I suppose, for instance, that, giving the example text, below :
Text to be deleted Recente Text to be deleted bla bla Coments 123456789 ABCDEF Tags bla bla bla that's the End
you would expect the resulting text :
Recente Coments Tags
Is my assumption correct ? If so, give me half an hour more, and I’ll post you the final regexes
Best Regards
guy038
-
Vasile,
Although, you have not reply to my question, yet, I suppose that I was right and here are the new regexes, to achieve such a result !
As said before, the first regex is UNCHANGED. Remember that it just marks any of the six blocks, wanted, with a special character,
#
( which must not be used, yet, in your files ! ) So this first S/R is :SEARCH
^\h*Recente\R(?=\h*Coments\R\h*Tags|\h*Tags\R\h*Coments)|^\h*Coments\R(?=\h*Recente\R\h*Tags|\h*Tags\R\h*Recente)|^\h*Tags\R(?=\h*Recente\R\h*Coments|\h*Coments\R\h*Recente)
REPLACE
#$0
=> After this global replacement, a sharp character,
#
, should have been inserted, at the beginning of the FIRST line of each block !
Now, perform, SUCCESSIVELY, the three S/R, below, by clicking on the Replace All button
SEARCH
(?-s)^#(?:.+\R){2}\K.*(Recente|Coments|Tags).*
REPLACE
\1
=> The third line, of each block, should have been modified
SEARCH
(?-s)^#.+\R\K.*(Recente|Coments|Tags).*
REPLACE
\1
=> The second line, of each block, should have been modified
SEARCH
(?-s)^#.*(Recente|Coments|Tags).*
REPLACE
\1
=> Finally, the first line, of each block, should have been modified
Et voilà !
IMPORTANT :
-
These three S/R must be run, in that EXACT order, to be sure that the temporary mark character,
#
, will be deleted during the last S/R, only !! -
Don’t use the Replace button for these three S/R, ONLY the Replace All one !!
Cheers,
guy038
-
-
hello guy38, I wasn’t here, sorry.
So, I test all your new regex. First, the long regex, replace by#$0
works very good.The little problem are the next 3 SUCCESSIVELY regex. One by one. After Search and Replace with
\1
, I get the successful message “6 occurrences has were replaced.”The problem is that, in fact, nothing has changed…is like nothing happen…
The last of the 3 successively regex
(?-s)^#.*(Recente|Coments|Tags).*
, after replace with\1
, removes the # sign witch I had put with the first long regex -
Oh, WORKS ! I use another example. So, excuse-me. All your regex works just fine guy38. You practically move all 3 words to the beginning of lines.
Thanks a lot
-
and, I return to my old problem. Now with your help, I manage to take all 3 words to the start of the lines. The question was, how can I mark/delete something before or after those 3 words. For example:
text bla Commens
text bla bla TagsRecente
Coments
Tagstext bla Recente
text bla bla TagsSo, you see that the words “Recente, Coments and Tags” are repeating. So, I manage to resolve my first problem: HOW TO DELETE EVERYTHING BEFORE THOSE 3 words on the 3 successively lines, included those 3 lines:
Search
((?s)((^.*)^Recente|^Coments|^Tags))(.*$)
Replace by:
Leave empty
-
Now, to delete everything after those 3 words (and 3 lines) included those 3 lines
Search:
^.*(?s)^Recente|^Coments|^Tags.*[\s\S]
Replace by:
leave empty
-
so, you see my friend, where I wanted to get. The single problem was that all that 3 words, were somewhere in the middle of the lines, and I didn’t know how to select those SUCCESSIVELY lines.
thanks a lot.
But If you know another 2 regex to do directly this, for deleting before and after, without adding the 3 words at the beggining at the lines, please let me know.
-
Vasile,
I’m just back on our forum and, after reading your post, where you said :
The problem is that, in fact, nothing has changed…is like nothing happen…
I quickly guessed why it did NOT work :-) Ah ! Again, I forgot to add this VERY IMPORTANT fact :
If your pattern regex contains one or more look-behinds AND/OR any
\K
form, you must, EXCLUSIVELY use the Replace All button to perform a global replacement.DON’T use the Replace button, for a step by step replacement : it does NOTHING !!
So, for performing, correctly, my three previous regexes :
(?-s)^#(?:.+\R){2}\K.*(Recente|Coments|Tags).*
(?-s)^#.+\R\K.*(Recente|Coments|Tags).*
(?-s)^#.*(Recente|Coments|Tags).*
with replacement
\1
-
Move the caret, before the text to change
-
Perform the three S/R, in that order, by clicking, EXCLUSIVELY, on the Replace All button ( Not the Replace button !! )
It should be OK
Of course, don’t forget to delete the extra
#
character, at the endCheers,
guy038
So, I updated my previous post !
-
-
WORKS !!!
-
A different nice regex looks like this. First check . match newline
Search:
.*\n([ \t]+Recente\s+Coments\s+Tags).*
REPLACE By:
$1
or\1
Don’t forget to check . match newline
This will select all that 3 words, even if are delimitaded by tab or spaces. And will delete the rest of document.
But how can I use this regex, to remove everything only before those 3 words, and another regex to remove only after those 3 words? -
or, without check . match newline
Search:
(?s).*\n([ \t]+Recente\s+Coments\s+Tags).*(.*$)
REPLACE By:
$1
or\1
-
hello, I find the solutions:
So, to delete everything before those 3 words, included the 3 lines with the words:
Search:
(?s).*\n([ \t]+Recente\s+Coments\s+Tags)
Replace By:
Leave Empty
Delete everything after those 3 words included the 3 lines with the words:
Search:
(?s)([ \t]+Recente\s+Coments\s+Tags)(.*$)
Replace by:
$1