Regex Group Optional

Hi Guys,

I have a question how to do an optional group in knime using regex split.
Here’s my sample code. Group by 1,2,3,4
1/(.asterisk)
2/(BRANCHES|HO|MERCHANT BANK|OTHERS|SUBSIDIARY BANK|SUBSIDIARY-NON BANK)
3/(?:([A-Z]{2}[0-9]+)_)?
4/(?:(.asterisk))?

I put “?” in group 3 & 4 to be optional in data pattern. Unfortunately it didn’t worked.

Thank you in advance

Hi,

Could you provide a workflow with a table creator node containing 1 or 2 examples?

When I tried I got this output:

Screen Shot 2022-06-27 at 2.22.35 PM

Screen Shot 2022-06-27 at 2.22.54 PM

Screen Shot 2022-06-27 at 2.23.04 PM

I think using (()) can cause issues here, but can’t be sure.

1 Like

Hi @victor_palacios

Thanks for your help, unfortunately it didn’t worked.

Here’s my sample data.
Sample output.xlsx (13.2 KB)

Thank you,

Here you go:

The main issue here was that the (.*) was capturing the white space which comes before the branches/subsidiaries/etc., but in your call for 2 letters and n numbers, you did not specify that the white space existed. This is why I added \s.

(.asterisk)(BRANCHES|HO|MERCHANT BANK|OTHERS|SUBSIDIARY-BANK|SUBSIDIARY-NON BANK)(\s[A-Z]{2}[0-9]+)?(.*)

As well, you did not use a hyphen for SUBSIDIARY-BANK which also caused issues.

3 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.