I am extracting the substring from a string using Regex extractor node but the string has multiple substrings that match to that regex. but I need to extract the first found string?
@qqilihq can you please help me with this?
I am not sure if non greedy also works in KNIME (sorry can’t test myself right now), but you could try your pattern with a “?”
e.g.
(.*?)
you would replace the dot star with your pattern.
Hi PankajChaudhary,
Could you post an example of your input and what you’re actually expecting?
–Philipp
@qqilihq
String: ABW-89^Description^Code^scfs
regex: (?<=^)(.*?)(?=^)
output: Description Code
I need only the first substring match with regex from the string.
Expected Output: Description
For the given example, you literally want “Description”? Then try this: [^\^]*\^([^\^]*)\^.*
-
[^\^]*\^
: read all characters until a^
is encountered, -
([^\^]*)
: then capture characters which are not^
, -
\^.*
: from there match rest of string
Or do you want “ABW-89”? then simply use ([^\^]*)\^.*
–Philipp
Not sure whether my idea would fit to your requirements. But what about using a Cell Splitter Node Cell Splitter — NodePit with “^” as delimiter?
This node splits the input string in different columns: In your example you get 4 columns with one string each
ABW-89 | Description | Code | scfs
Unfortunately the node is deprecated.
Thanks, @qqilihq your suggestion helped me to solve my problem.
Thank you so much.
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.