Regex Split with Positive Lookahead

 

 I'm trying to use the Regex Split-node match all the characters in a string before the first occurence of a underscore. (e.g. BBBB_WWWW should match the BBBB). Using the following regex (with positive lookahead) usually works: 
.*?(?=_)
However, since Knime requires that I put brackets around the match group I have to input something like 
(.*?)(?=_)
which does not show the required behavior. How can I resolve this issue? My goal is to retain the part before the underscore (size may vary).

How about

(.*)_.*

? This should match everything before the first underscore and skip the rest.

Dominik

Hi Dominik,

Thank you for your reply. Unfortunately this does not work, the complete string AAA_BBB_CCC is matched instead of only the AAA part. I have tested the regex .*?(?=_) in an online Regex tester and it worked fine. I suppose the problem lies with KNIME requiring the brackets around the match group, so it confuses the lookahead with a match group.

 

EDIT: The reason your regex didn't work is because of the (.*), it matched everything. I edited it  to:

(.*?)_.*

and it works fine now. Thanks!