Creating Line Break when there are multiple spaces on tagged line.
-
I am probably pushing my luck with getting more help, as I got some great help already. But I am trying to accomplish a huge project with very little regular expression experience. Any help would be greatly appreciated! Thank you!
On any line that starts with C2: to create a new line when there is 3 spaces. And also create the C2: tag on the new line.
Sample:
[Y:prn]
[C0:MNB WT REPORTS]
[D:8/7/2019 11:07:29 PM]
[C9:5]
[C1:SynergyExport/440919]
[C2:WT2400P Wire Transfer Notices]
[C10:661703]
[Y:prn]
[C0:MNB AA REPORTS]
[D:8/7/2019 11:07:29 PM]
[C9:5]
[C1:SynergyExport/440920]
[C2:BSFRG00294 User Profile Changes]
[C10:661704]Outcome:
[Y:prn]
[C0:MNB WT REPORTS]
[D:8/7/2019 11:07:29 PM]
[C9:5]
[C1:SynergyExport/440919]
[C2:WT2400P
[C2:Wire Transfer Notices]
[C10:661703]
[Y:prn]
[C0:MNB AA REPORTS]
[D:8/7/2019 11:07:29 PM]
[C9:5]
[C1:SynergyExport/440920]
[C2:BSFRG00294
[C2:User Profile Changes]
[C10:661704] -
@ashley-hoogenboom said in Creating Line Break when there are multiple spaces on tagged line.:
On any line that starts with C2: to create a new line when there is 3 spaces
I don’t see any C2 lines with 3 spaces.
You aren’t following the guidelines for posting for this sort of help.
See HERE for that. -
Take this with a grain of salt, as this is my first attempt at helping with this stuff that’s not mine. :)
S/R:
Find what:^(\[C2:)(\w+)(.*)
Replace with:$1$2\n$1$3
This worked for me with your example text, so take it for what it’s worth.
Lee
-
@ashley-hoogenboom said in Creating Line Break when there are multiple spaces on tagged line.:
On any line that starts with C2: to create a new line when there is 3 spaces
Ok, a few ways to interpret that… :-)
You meant (roughly) word-space1-word-space2-word-space3-word. 3 spaces. Got it. -
Thank you for guiding me to the template…that makes it a lot easier. I will be sure to use that moving forward.
Fellow Notepad++ Users,
Could you please help me the the following search-and-replace problem I am having?
On any line that starts with C2: to create a new line when there is 3 spaces. And also create the C2: tag on the new line.
Here is the data I currently have (“before” data):
[Y:prn] [C0:MNB WT REPORTS] [D:8/7/2019 11:07:29 PM] [C9:5] [C1:SynergyExport/440919] [C2:WT2400P Wire Transfer Notices] [C10:661703] [Y:prn] [C0:MNB AA REPORTS] [D:8/7/2019 11:07:29 PM] [C9:5] [C1:SynergyExport/440920] [C2:BSFRG00294 User Profile Changes] [C10:661704]
Here is how I would like that data to look (“after” data):
[Y:prn] [C0:MNB WT REPORTS] [D:8/7/2019 11:07:29 PM] [C9:5] [C1:SynergyExport/440919] [C2:WT2400P [C2:Wire Transfer Notices] [C10:661703] [Y:prn] [C0:MNB AA REPORTS] [D:8/7/2019 11:07:29 PM] [C9:5] [C1:SynergyExport/440920] [C2:BSFRG00294 [C2:User Profile Changes] [C10:661704]
I am not really sure where to begin, I’m a beginner. But really want to learn!
Find What =
^([C2:)
Replace With =
Search Mode = REGULAR EXPRESSION or NORMAL or EXTENDED
Dot Matches Newline = CHECKED or NOT CHECKED
HERE IS WHY YOU THOUGHT YOUR EXPRESSION WOULD WORKUnfortunately, this did not produce the output I desired, and I’m not sure why. Could you please help me understand what went wrong and help me find the solution?
Thank you.
-
@ashley-hoogenboom said in Creating Line Break when there are multiple spaces on tagged line.:
[C2:WT2400P Wire Transfer Notices]
Ah ha! Another definition of “3 spaces”! :-)
@ashley-hoogenboom said in Creating Line Break when there are multiple spaces on tagged line.:
But really want to learn!
We like people like that! :-)
-
@alan-kilborn said in Creating Line Break when there are multiple spaces on tagged line.:
Ah ha! Another definition of “3 spaces”! :-)
Yes, sorry the first time when I copied it over it didn’t keep the additional spacing.
-
Try:
find:
(?-s)^((\\[C2:)\w+)\x20{3}(.+)\\](\R)
repl:${1}]${4}${2}${3}]${4}
search mode: regular expression -
Then you need to better prepare your example texts so someone doesn’t ignore you in exhaustion. Like you, I didn’t know crap about this Regex stuff until I needed to learn here with these good people’s help, but I always gave them exactly what I was using, what I needed and how it should look. This of course, is after I had beat my head silly trying to learn this on my own, so I at least had an inkling of what they were telling me in response…even if I didn’t understand what it was. I suggest you do the same. Learn what you can, then ask questions as you go, but changing the goal posts of what you want from the same piece of text is on you.
Honestly, I’ve been following this forum in the background and now I understand the frustration these folks have gotten to, trying to help people that don’t have an inkling of what it is they really want and expect people to read their intentions, rather than their needs.
Lee
-
-
@lycan-thrope said in Creating Line Break when there are multiple spaces on tagged line.:
Then you need to better prepare your example texts
A bit harsh. You don’t know what you aren’t doing right until someone tells you, most times…
The OP seemed very agreeable to read the info I pointed to, and rework the question/data to conform.
-
Perhaps, but I was the recipient of like until I got the system right, too. Mostly my problems stemmed from trying to describe the problem without knowing what the forum’s formatting norms were. It was my bad…and I was called on carpet about it, too, appropriately. :)
Interestingly, my solution should have worked for him, anyway, spaces or not.::shrug::
Lee
-
@alan-kilborn said in Creating Line Break when there are multiple spaces on tagged line.:
(?-s)^(([C2:)\w+)\x20{3}(.+)](\R)
Thank you! That worked! If you have time can you explain that to me. If not I will be looking it up to make sense of it all.
-
@ashley-hoogenboom said in Creating Line Break when there are multiple spaces on tagged line.:
If you have time can you explain that to me
(?-s)^(([C2:)\w+)\x20{3}(.+)](\R)
(?-s)^((\[C2:)\w+)\x20{3}(.+)\](\R)
- Use these options for the whole regular expression
(?-s)
- Assert position at the beginning of a line (at beginning of the string or after a line break character) (carriage return and line feed, form feed, next line, line separator, paragraph separator)
^
- Match the regex below and capture its match into backreference number 1
((\[C2:)\w+)
- Match the regex below and capture its match into backreference number 2
(\[C2:)
- [Match the character “” literally
\[
- Match the character string “C2:” literally (case sensitive)
C2:
- [Match the character “” literally
- Match a single character that is a “word character” (Unicode; any letter or ideograph, digit, letter number, underscore)
\w+
- Match the regex below and capture its match into backreference number 2
- Match the character “ ” which occupies position 0x20 (32 decimal) in the character set
\x20{3}
- Exactly 3 times
{3}
- Exactly 3 times
- Match the regex below and capture its match into backreference number 3
(.+)
- [Match the character “]” literally]3
\]
- Match the regex below and capture its match into backreference number 4
(\R)
${1}]${4}${2}${3}]${4}
- Insert the text that was last matched by capturing group number 1
${1}
- [Insert the character “]” literally]4
]
- Insert the text that was last matched by capturing group number 4
${4}
- Insert the text that was last matched by capturing group number 2
${2}
- Insert the text that was last matched by capturing group number 3
${3}
- [Insert the character “]” literally]4
]
- Insert the text that was last matched by capturing group number 4
${4}
Created with RegexBuddy
- Use these options for the whole regular expression
-
@lycan-thrope Thank you for your willingness to try and help me as well. I am new to this site as of last night, and I will be sure to follow the rules and make sure I am giving the correct sample. :-)
-
@alan-kilborn Amazing! Thank you so much
-
@ashley-hoogenboom ,
All they can ask. I feel for these guys that do this day in and day out. You were my first attempt, and I was kind of angry when you changed the goal. :) That said, welcome to the NPP forum, community and ask away. The only stupid question, is the one not asked. :)Lee