How do I add text to each line?
-
I have the following text :
ernestobaltar@yahoo.com:Golden-Ball amaury.tenaille@epfedu.fr:SilverBall Inspirit@staplesnet.us:Copper_Ball Matthewsk@mail.montclair.edu:Encourage sissleib6930@stu.howardcollege.edu:Not-Engaged
I want to get result :
ernestobaltar@yahoo.com:Golden-Ball:Email.yahoo.com amaury.tenaille@epfedu.fr:SilverBall:Email.epfedu.fr Inspirit@staplesnet.us:Copper_Ball:Email.staplesnet.us Matthewsk@mail.montclair.edu:Encourage:Email.mail.montclair.edu sissleib6930@stu.howardcollege.edu:Not-Engaged:Email.stu.howardcollege.edu
How do I do?
-
We’ve been through this before. We have shown you plenty of regex that deal with your colon-separated files. Try generalizing one of those approaches (I will give you a hint: start with @guy038’s most recent post in your previous question).
If what you tried doesn’t work, show us what you tried, and explain why you thought it would work. We will then be able to help you learn what you are missing.
This forum is not a place where we do your job (or your homework) for you. We have explained plenty of times what the various portions of our regexes do. We have pointed you to the documentation plenty of times. You have complained that you don’t have the time to read the documentation… but somehow, you have the time to come here with every new situation with these colon-files, and then the time to wait for answers, and then the time to argue with us when we try to get you to make an effort. Honestly, if it’s not important enough to you to read some documentation, why should it be important enough to us to do it for you?
Show some effort, and you will get good answers. If you refuse to show effort, well, then, good luck.
-
Hello, @sarah-duong, and All
I was about to give you the full solution to your problem, when I saw the @peterjones’s answer. And I must admit that he’s right about it !
So let me show you how to guess the right solution as your goal is, simply, a line substitution of some parts of current line !
You said that you have, for instance, this last line of text :
sissleib6930@stu.howardcollege.edu:Not-Engaged
and that you want it to be changed as :
sissleib6930@stu.howardcollege.edu:Not-Engaged:Email.stu.howardcollege.edu
OK ! So, let’s try to decompose, both the initial and the expected lines, inserting some
space
chars for a best identification of the different parts of your text :INITIAL : sissleib6930 @ stu.howardcollege.edu : Not-Engaged EXPECTED : sissleib6930 @ stu.howardcollege.edu : Not-Engaged :Email. stu.howardcollege.edu
What do we see ?
-
Firstly, the initial line must be rewritten as is
-
Secondly, the literal string
:Email.
must be added at the end of current line -
Thirdly, the site address, located after the
@
symbol and before the:
symbol must be added, too, after the literal string:Email.
Now, it should be easy enough to you to build up the correct regex S/R to perform such modifications !
You may find some first help, reading this part of the N++ official documentation :
https://npp-user-manual.org/docs/searching/#regular-expressions
I can assure you that my complete solution, already found, respects exactly the scheme described above !
This is not surprising because there can only be one valid interpretation, though there can be several regex valid syntaxes, of course !
Best Regards
guy038
-
-
@PeterJones You have the right to not answer my question. And I have the right to ask questions in this forum. Please tell me what I did wrong something? You see you say these things is very redundant, if I use multiple accounts to log multiple topic? You can check that? I do not understand my problem. You are trying to impose someone else? I do not know, I asked. And obviously I did not post one question 2 times. All content is different I clearly asked.
If you feel my question is beyond the ability, you can ignore it, or support others. I not only ask you to support me. For example in this topic, I do not understand what guy038 said, I also complain about things? Looking back the way your show, you have properly? 1 again and you tell me, I do something wrong? -
@guy038 Perhaps it is only for those who know how to build one regex. For me, it’s not. Anyway, thank you for answer.
-
Hi, @melad-eissa,
In my previous post, I give an example of the modifications needed :
INITIAL : sissleib6930 @ stu.howardcollege.edu : Not-Engaged EXPECTED : sissleib6930 @ stu.howardcollege.edu : Not-Engaged :Email. stu.howardcollege.edu
Seemingly, we need the part between the
@
and the:
chars because this part has to be re- written at the end of line, tooHowever, the part before the
@
char does not change at all. So we can represent the goal as below ( note thatSpace
chars are irrelevant )The OVERALL match = $0 /¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯\ INITIAL Text @ stu.howardcollege.edu : Not-Engaged EXPECTED Text @ stu.howardcollege.edu : Not-Engaged :Email. stu.howardcollege.edu \___________________/ \_____/ \___________________/ Group 1 String Repeated Group 1 SEARCH regex @ ( .+ ) : .+ REPLACEMENT regex $0 :Email. \1
Now, the exact syntax of this regex S/R is rather obvious :
SEARCH
(?-s)@(.+):.+
REPLACE
$0:Email.\1
And will change the initial text :
ernestobaltar@yahoo.com:Golden-Ball amaury.tenaille@epfedu.fr:SilverBall Inspirit@staplesnet.us:Copper_Ball Matthewsk@mail.montclair.edu:Encourage sissleib6930@stu.howardcollege.edu:Not-Engaged
into the expected text :
ernestobaltar@yahoo.com:Golden-Ball:Email.yahoo.com amaury.tenaille@epfedu.fr:SilverBall:Email.epfedu.fr Inspirit@staplesnet.us:Copper_Ball:Email.staplesnet.us Matthewsk@mail.montclair.edu:Encourage:Email.mail.montclair.edu sissleib6930@stu.howardcollege.edu:Not-Engaged:Email.stu.howardcollege.edu
Notes :
-
In the search regex :
-
First, the
(?-s)
ensures that any regex symbol.
will match a single standard character, only and notEOL
chars -
Then the part
@(.+):
searches for the@
character followed with a non-null range of chars till a colon:
. Note that this range is stored as group1
because of the parentheses -
The final part
.+
represents the characters after the colon char of each line
-
-
In the replacement regex :
-
We first insert the overall pattern
$0
. So, everything between the@
char and the end of current line -
Then, we write the literal string
:Email.
-Finally, we re- write the contents of Group
1
, so the name of each site, thanks to the\1
syntax -
Best Regards,
guy038
-