I am not so familiar with REGEX and would appreciate a little help. In a string cell with text like
1. text. 2. othertext. 3. justanothertext...and so on
I want to insert a newline/carriage return just before the numbers with the StringReplacer to get the following result:
1. text.
2. othertext.
3. justanothertext...and so on
I use ( )([0-9]{1,3}\. ) for the text to replace which seems to work and \n$2 for the replacement text. It inserts the numbers again but not the new line. Instead I get a 'n1.' for example.
I get rn1. as replaced text. The String Replacer does not seem to recognize special characters like \r or \n and when I choose 'Regular expression' the 'use backslash as escape character' is dimmed.
Also wondering if this was ever solved. I have caught myself needing this several times in the past and always have to find a different solution. I seem to stumble across this multiple times here and there. Any help is appreciated. Thanks in advance.
I see. I tried to replicate yours but the output wasn’t the same. That’s okay. The output file I get only contains spaces. I tried “\s” and “\s”+ with no luck. I have also tried for example: regexReplace(column(“Column”),“(IPsec)+(:\s)+(.+)”,“\n”) for the following use case:
input
abcdefgh256 IPsec: (2)AES256
output
abcdefgh256
IPsec: (2)AES256
I am finding amazing that a single CR on an editor it’s seeming to be very hard on such powerful tool such as Knime. I really hope I am wrong and there’s a node out there to simply add a CR based on a specific word it finds along the text sending it to the new line, as well as a ‘white space’ trim for beginning of lines. I have been trying ‘Column Expressions’ with ‘strip(" ") or double space’ and ‘stripStart(" ")’ without any luck.
Also, unfortunately \n is not acting as expected for me no matter what I try. I have tried to even simply match the expression. “IPsec” and then skip the line w no luck. The regex matched on regex101.com but didn’t do the expected on the function.
Make sure you take along the Java compatible version from regex101 to KNIME by using the Code Generator, Java and the contents of the final String regex
@ArjenEX absolutely it did. I knew there was some sort of different regex just had no idea which one would be. That will definitely help me. Thank you! Last question about this.
After I added a new line. By opening this on excel and selecting the wrap cell function, I can see the second line on the cell. So far so good. Coping the entire column to a Notepad, I get quotes from the beginning of the line to the end, like this:
“Encryption : IKEv2: (1)AES256
IPsec: (2)AES256”
I do not see these quotes on Knime. I suppose there may be a way to remove them.
2nd to last. I have several words that will need to be added to the same exact expression of ‘Column Expression’, anyway I can use this with variables and/or some sort of dictionary?
Last but not least, how can split this double-line row into two single line rows?
Hi @jarviscampbell , here is another possible way to do similar manipulation without using regex. I don’t know if it is suitable in your case, but possibly useful to see other ways too. The last part may assist with you question re splitting a cell into a new row.
Thank you so much @takbb , I will see if your option works for me tomorrow w a different problem. I believe regex might do it at this point for this one. I appreciate the help.
Hi @takbb I tried your solution actually, w my current data. Unfortunately using colon instead of a tab to split (which is what would work for me based on what I have, gave me strange output)
I’ve started from the point that I already had some sort of ‘column aggregated’ since I have eg: < Connection:8.8.8.8 > data already. Ideas?