REGEX Not Working

I am having trouble with REGEX find and replace. When I use online testers, the code works. I tested it in a Java tester, Javascript tester, and others. Here is what the data looks like:

ASAP, , , 
ASAP, Manual, , 
ASAP, , , 
ASAP, , , 
Device Issues, Manual, , 
Device Issues, , , 
Device Issues, Manual, , 
Device Issues, , , 
Device Issues, Manual, , 
Device Issues, , , 
Device Issues, , , 
Investigate, Manual, , 
Investigate, QA, , 
Investigate, , , 
 

and here is my code:

,\B(\s\W){1,}

The object is to remove all of the trailing ", " (that's comma and space), with the exception of those that are in between the words.

When I put the code in KNIME, it doesn't work like it is supposed to work.

Hi cageybee, 

If you look at the node description of the String Manipulation node, you can see that special characters such as backslashes need to be escaped using a backslash. For instance, a single backslash in a string is written as two consecutive backslash characters; the first one acts as the escape character for the second.

The same holds if you're replacing your string with a Java Snippet node.

So just use ,\\B(\\s\\W){1,} instead of ,\B(\s\W){1,} and it will work. 

I also tried to remove the trailing commas with (\,\s)+(\W|\s), you can find attached a sample workflow with both solutions and a Java Snippet node solution. 

 

Best,

Anna

Thank you, Anna.