I have a query that concatenates the values of two columns and returns a string as shown below:
423545(50),AXX-10, ABB-1234X(30), 7568787(50),53654656,2021947(50),ABCD-2343423,FDKHD-324342(20),
I would like to split that string and put it in an array discarding all the values in the brackets. The output to be as shown below:
[423545,AXX-10, ABB-1234X, 7568787,53654656,2021947,ABCD-2343423,FDKHD-324342]
- The comma at the end of the string is optional
- Not all the columns contain the bracketed values
I know i can use String.split() but the optional bracketed values and comma at the end of the string complicates it.
Thanks in advance.
You can split on two patterns: –
\\(\\d+\\),[ ]*, which will take care of bracketed terms,[ ]*, which will work for normal,separated values.You just need to merge those regex using a
pipe(|), and perform the split at once.So, your split criteria becomes: –
which can be further simplified to: –
We just made a part optional, and took the common part outside.