Using regex_replace filter in removing empty lines
SOLVE
I'm currently trying to use regex_replace filter to remove empty lines.
Below is the script i'm trying to convert to hubl.
var stringWithLineBreaks = `
Lorem ipsum dolor sit amet
- 11.6" HD (1366 x 768) Lorem ipsum
- Consectetur adipiscing elit
- Sed do eiusmod tempor
- Incididunt ut labore
- Et dolore magna aliqua.
- Consectetur adipiscing elit
`;
var stringWithoutLineBreaks = stringWithLineBreaks.replace(/^\s*[\r\n]/gm,'');//remove empty lines
console.log(stringWithoutLineBreaks);
Regexes provided also won't work and there's not a way to definitively tell you which will "work" without clearly stated bounds / expectations. Assuming your text is as copied verbatim - just simple newlines without any "non-printable" characters, isn't from rich text / contains HTML in the "real" source as Gonzalo noted, and other similar cases a very simple one is just replacing consecutive newlines / escape sequences with the edge case of the last new line.
You could do something like:
regex_replace("(?m:^[\\s\\t\\n\\r])+|\\n$","") - The OR operator here just strips last newline as it's the edge case...
Or, simpler
regex_replace("(?m:\\n$)","") if it's just simple newlines....
Or, normalizing the first... if it has mixed sequences.
regex_replace("(?m:[\\s\\t\\r\\n]+$)","")
Or, an infinite other number of regex that are, again, entirely dependent on your use case and boundaries. The missing case in all of these is, again, HTML, hidden character sequences / non-printable ones etc. I'm sure even given regexes could be improved I wasn't really going for "optimized" here. I was going for "illustrative", so take them cautiously and I didn't test these either. So, there's also that along with the fact I haven't used regexes in quite some time 😉
Also worth noting that if it's just simple newlines... You don't even need a regex to do this if you find them overly complex. Simple string ops suffice.
@dennisedson Still patiently waiting for unicode operations to be unblocked that are accepted, but yet magically don't work with the filter 🙄
Using regex_replace filter in removing empty lines
SOLVE
Thanks @Ntbrown, I used the first one and it worked. It's think it removed the empty lines, and empty spaces before, after and inbetweent text, whch is what just I needed.
I used js to remove the lines, but I just wanted to maximize the use of Hubl
Regexes provided also won't work and there's not a way to definitively tell you which will "work" without clearly stated bounds / expectations. Assuming your text is as copied verbatim - just simple newlines without any "non-printable" characters, isn't from rich text / contains HTML in the "real" source as Gonzalo noted, and other similar cases a very simple one is just replacing consecutive newlines / escape sequences with the edge case of the last new line.
You could do something like:
regex_replace("(?m:^[\\s\\t\\n\\r])+|\\n$","") - The OR operator here just strips last newline as it's the edge case...
Or, simpler
regex_replace("(?m:\\n$)","") if it's just simple newlines....
Or, normalizing the first... if it has mixed sequences.
regex_replace("(?m:[\\s\\t\\r\\n]+$)","")
Or, an infinite other number of regex that are, again, entirely dependent on your use case and boundaries. The missing case in all of these is, again, HTML, hidden character sequences / non-printable ones etc. I'm sure even given regexes could be improved I wasn't really going for "optimized" here. I was going for "illustrative", so take them cautiously and I didn't test these either. So, there's also that along with the fact I haven't used regexes in quite some time 😉
Also worth noting that if it's just simple newlines... You don't even need a regex to do this if you find them overly complex. Simple string ops suffice.
@dennisedson Still patiently waiting for unicode operations to be unblocked that are accepted, but yet magically don't work with the filter 🙄
Using regex_replace filter in removing empty lines
SOLVE
Hi,
Not sure if i can help on this 😉 will try my best!
First i will identify txt format is a txt or enrichtxt or HTML?. (the payload) . Second i will try to add (\l) to your command line.
Other work arround. I understand you are looking to wrangle as a "make-up". I suggest you to clean it before, you can do this with the new HubSpot Hub Operations with in a workflow. ( the have some tranformation out-of-the-box new commands) or you can use apps like Trifacta or dataprep to do this.