Skip to main content

I'd like to use non capturing groups in StringSearch. It is possible in the PCRE expression but seems not to work in FME :

Example :

On the string "This is a text string"

(?:This is )(\\w)* should return only the string "a", but StringSearch returns the whole "This is a" in the "first_match", and only "a" in the subgroup when activated.

First match should be the same as the first subset ?

@jedi121​  StringSearcher is giving you the result you want, probably just not in the place that you'd expect find it. When you are using the regex editor in FME it shows all of the matched characters:

2020-09-04_14-47-41

Then in the StringSearcher parameters, you have to use the Advanced panel to generate a list of the sub-expressions that are to be captured;

2020-09-04_14-50-03

And then, you'll only see the results in Data Inspector / Visual Preview if you open the Feature Information window:

2020-09-04_14-51-53

Not to dissimilar to what https://regexr.com/ shows you - which is a great tool for testing and understanding regex expressions.


As @Mark Stoakes​ indicates, the return values for RegEx capable Transformers and Functions return the whole matching pattern as the default value to return, and not any particular group. This is why you get the full matching pattern back.

 

However, FME does support Groups in most RegEx Transformers and Functions, you just need to know how to call for the specific Group values. In FME, this is achieved by calling for the Group by writing "\\1" for Group 1's value and "\\2" for Group 2's value etc.

 

A general purpose way is to use StringReplacer. In the Replacement Text Parameter, if you instead use "\\1", then it will return the text within Group 1.

 

Similarly, using AttributeCreator with the String Function @ReplaceRegEx(@Value(TextAttributeToSearch), "(?:This is )(\\w)*", \\1), will return the first Group. Using @ReplaceRegEx(@Value(TextAttributeToSearch), "(?:This is )(\\w)*", \\2) will return the second Group etc.

 

 


Reply