@Wahlla-Magla said in Need help please:
@PeterJones
the reference post had nothing to do With this post, I certainly can’t apply the same regx and they are Two opposite things.
The same regex – of course not. I never said you could. But it has the same concepts. And I will prove that below.
I posted this so that someone can help me fix it because I couldn’t find it Someone else.
I appreciate the work you’re doing and I understand that you’re doing it for free and I’m not here to argue I just need help, I use notepad++ every day And I’m definitely learning.
You posted this so that we’d do your work for you. And you got it again this time. Lucky you. But if you haven’t figured out the concepts of the previous regex in the more-than-1.5-years since that last post, it’s really hard for us to believe you are really here to learn instead of trying to guilt us into doing your work for you.
So here is a description of the concepts that Alan’s regex from 2021 should have taught you, and an exaplanation of how the concepts that were presented in your previous question are exactly the same concepts you are still working with here – at the same time, giving you the answer you wanted to this specific problem.
In the previous post, you had some colon-separated text
item:email:item:password:item:item:item:item:item:item:item:item:item
and wanted to do something with text between the colons, but only specific fields.
In this post, you have colon-separated text
1111:55555:8383:jjjsyn:ayahj:jsjsja:jjsjjsjjs
and want to do something with the text between the colons, but only for specific fields.
In the previous post, the search (?-s)^.+?:(.+?):.+?:(.+?):.+ grabbed the second and fourth fields from your colon-separated text, and ${1}:${2} did the replacement so everything was replaced with just groups#1 and #2 (which were your second and fourth fields) with a colon between
This time, what you want is to grab the text from the first and second fields, and replace it with the same text, but with no colon between.
So the concepts involved:
you want to start at the beginning of a line, so that you know which field you are in at any point in the regex – this was true of both. You do this with the ^ anchor
you want to be able to temporarily store the contents of one or more of the fields – this was true of both. As Alan showed you in 2021, you do this by the (.+?) sequence
you want to split the fields based on the colon – both last time and this time. Using the : in the regex in the right places does exactly that.
you want to replace some or all of the line with the contents of groups you saved – you wanted this before, and you want it this time. The difference is that before, you wanted to replace the whole line with those contents, and this time, you only want to replace part of the line with those contents.
So to evolve the old regex into the new:
The groups you care about are the first and second instead of the second and fourth. So that will change the regex from (?-s)^.+?:(.+?):.+?:(.+?):.+ to (?-s)^(.+?):(.+?):.+?:.+?:.+
You don’t want to affect anything after the second colon from the original text. So that will mean you don’t need to continue the match beyond the second colon in the regex, so just trim it down: (?-s)^(.+?):(.+?): – now it just matches the first two fields and the colons that follow them. (I included the second colon to help anchor things)
You want to replace that smaller matched section with the contents of the groups, and (since I included the trailing colon) a colon after, but no colon between. So you take the original replacement from the previous discussion, ${1}:${2}, which put a colon between the group#1 and group#2, and instead just want the two groups together with a colon after, like ${1}${2}:
In the end, you end up with
FIND = (?-s)^(.+?):(.+?):
REPLACE = ${1}${2}:
with just a couple of quick changes to the previous regular expression
With initial text
1111:55555:8383:jjjsyn:ayahj:jsjsja:jjsjjsjjs
6262g:yysh:ysyahj:hjjma:ksksygg:jsjjsj:jsjjsjz
and doing Replace All with the find/replace I showed above, I get
111155555:8383:jjjsyn:ayahj:jsjsja:jjsjjsjjs
6262gyysh:ysyahj:hjjma:ksksygg:jsjjsj:jsjjsjz
That is the text you said you wanted to get.
Thus, I have shown you that it was exactly the same concepts involved for breaking the line of text into fields, and exactly the same concepts involved for doing the replacement.
Stop lying to yourself: you can learn this, but you have to put in the effort to do so – and since you couldn’t see that it was the same ideas this time as last time, it shows that you haven’t put in the effort to understand. I’ve given you the blow-by-blow description for the slight changes necessary this time, in the hopes that you will start to see the concepts behind the regex, so that you can continue to customize those same ideas next time.