I want to create a new attribute from a regex pattern found in another existing attribute. If no pattern found then default to static value. Say for example, attribute bID has values 1<a>4, 44<a>, 98. My new attribute would be code1 would have values a, a, d. The regex finds the 'a' and 'd' is the default if no 'a' is found. I have played around with a series of transformers, but my solutions are clunky. Can someone propose an efficient solution? I'm struggling a bit with how to use the text editor to return a found regex pattern. Still learning! Also, I want to stick with implementing regex code because my actual problem may have a more complex regex pattern.
Thank you,
Tyler
FME2020.2.1.0 Win64



You could do something like this in an attributecreator, but returning the matched regex is more complicated, especially if like you say, the regex you will be using is more complicated. This example tests for the presence of the regex, if -1 is returned it means no match and a default value is set, otherwise everything that does NOT match the regex is replaced with nothing (leaving just the matched value)


clause from tester transformer
I've attached an example workspace.
The conditional for 'Code' simply tests whether 'Code' has a value and if not set 'Code' = "<Default>".