Skip to main content

I'm trying to use the FindRegEx Feature Function within the Expression Evaluator Transformer.

Does anybody know the correct syntax to use ?

Documentation on this seemed a little thin on the ground / no specific examples.

..........................

I'm trying to do a search in the field: [Category]

using the RegEx expression: 0[0-1][0-9]

I tried the following - but no luck:

@FindRegEx (@Value (Category), 0[0-1][0-9])

............................

Any ideas - most welcome

.............................

Regards

Howard L'

Hi @howard_l - It would be useful to have some context of what you are using the regular expression for, what problem you are trying to solve. If you are looking to test an attribute contains specific digits, then you might find it easier to use the StringSearcher with your regular expression - I tend to use this transformer.

With the StringSearcher transformer you specify the attribute to test in the 'Search In' field, then enter your regular expression and features are output via the Matched or NotMatched ports.

Depending on what you want to do you might want to extend the regex to restrict where the pattern you are searching for must appear in a tested value, for example

^0[0-9][0-9] would 'pass' the value 012, but not the value 1012 - ^ restricts the start

^0[0-9][0-9]$ would 'pass' the value 012, but not the value 0121 - $ restricts the end

But it depends what you are trying to do.


Hi @howard_l - It would be useful to have some context of what you are using the regular expression for, what problem you are trying to solve. If you are looking to test an attribute contains specific digits, then you might find it easier to use the StringSearcher with your regular expression - I tend to use this transformer.

With the StringSearcher transformer you specify the attribute to test in the 'Search In' field, then enter your regular expression and features are output via the Matched or NotMatched ports.

Depending on what you want to do you might want to extend the regex to restrict where the pattern you are searching for must appear in a tested value, for example

^0[0-9][0-9] would 'pass' the value 012, but not the value 1012 - ^ restricts the start

^0[0-9][0-9]$ would 'pass' the value 012, but not the value 0121 - $ restricts the end

But it depends what you are trying to do.

Great suggestion the use the transformer StringSearcher in this case! @1spatialmary

 


1spatialmary,

Thanks for your answer - but the query that I have isn't really about any particular regex expression as such - that isn't important.

Yes, I'm also aware of the StringSearcher and other Transformers that can also use regex - and they are very useful.

.............

The question I have is about the syntax that you need to use for the FindRegEx Feature Function within the Expression Evaluator Transformer - what is the syntax ??? Are there any examples for this ??? Especially examples for extracting values from a field.

..............

Regards

Howard L'


1spatialmary,

Thanks for your answer - but the query that I have isn't really about any particular regex expression as such - that isn't important.

Yes, I'm also aware of the StringSearcher and other Transformers that can also use regex - and they are very useful.

.............

The question I have is about the syntax that you need to use for the FindRegEx Feature Function within the Expression Evaluator Transformer - what is the syntax ??? Are there any examples for this ??? Especially examples for extracting values from a field.

..............

Regards

Howard L'

@howard_l, there is this link Syntax Regex, you can see it.

 

 

 


@howard_l, there is this link Syntax Regex, you can see it.

 

 

 

Documentation about String Functions Documentation

 

 


Hi @howard_l

@FindRegEx(@Value(CATEGORY),0[0-1][0-9]) is the correct syntax.

@FindRegEx returns position where the text you are looking for starts or -1 if nothing matches the regex, i.e. if CATEGORY = abc012abc, @FindRegEx(@Value(CATEGORY),0[0-1][0-9]) will return 3.


I found there are excess white spaces between the function name and subsequent round bracket. FME function syntax does not allow inserting spaces between function name and subsequent bracket.

wrong syntax

@FindRegEx (@Value (Category), 0n0-1]E0-9])

correct syntax

@FindRegEx(@Value(Category), 0d0-1]i0-9])

As well, the regex has a leading space. It's valid as syntax, but I don't think that you intend to set a regex containing a leading space. 

If the expression you have posted is the actual parameter setting in the ExpressionEvaluator, try removing the excess spaces.


I found there are excess white spaces between the function name and subsequent round bracket. FME function syntax does not allow inserting spaces between function name and subsequent bracket.

wrong syntax

@FindRegEx (@Value (Category), 0n0-1]E0-9])

correct syntax

@FindRegEx(@Value(Category), 0d0-1]i0-9])

As well, the regex has a leading space. It's valid as syntax, but I don't think that you intend to set a regex containing a leading space. 

If the expression you have posted is the actual parameter setting in the ExpressionEvaluator, try removing the excess spaces.

Takashi,

 

Thanks very much for your comments - really useful.

 

.............

 

Within ExpressionEvaluator the only RegEx function visible is FindRegEx (under String Functions).

 

Is it possible to use Contains RegEx or Match RegEx within the ExpressionEvaluator ???

 

(this is what I'd really like to do).

 

 

So far I've had no luck with any of these:

 

@Matches RegEx(@Value(Attribute1),building)

 

@MatchesRegEx(@Value(Attribute1),building)

 

@Contains RegEx(@Value(Attribute1),building)

 

@ContainsRegEx(@Value(Attribute1),building)

 

 

Is it possible ???

 

If so, what is the correct Syntax ?

 

...........

 

Regards

 

Howard L'

 

 

 


I found there are excess white spaces between the function name and subsequent round bracket. FME function syntax does not allow inserting spaces between function name and subsequent bracket.

wrong syntax

@FindRegEx (@Value (Category), 0n0-1]E0-9])

correct syntax

@FindRegEx(@Value(Category), 0d0-1]i0-9])

As well, the regex has a leading space. It's valid as syntax, but I don't think that you intend to set a regex containing a leading space. 

If the expression you have posted is the actual parameter setting in the ExpressionEvaluator, try removing the excess spaces.

I've never seen both @MatchesRegEx and @ContainsRegEx functions. Where did you find them?

 

 

See here to find all the available FME String Functions: FME Workbench | String Function

 

 

Note: In the ExpressionEvaluator (equivalent to the Arithmetic Editor), only the String Functions which return a numeric value are visible. If you want to use other String Functions to create a string value, consider using the StringConcatenator (Advanced Mode) or the Text Editor for parameter fields in the AttributeCreator or AttributeManager etc.
I've never seen both @MatchesRegEx and @ContainsRegEx functions. Where did you find them?

 

 

See here to find all the available FME String Functions: FME Workbench | String Function

 

 

Note: In the ExpressionEvaluator (equivalent to the Arithmetic Editor), only the String Functions which return a numeric value are visible. If you want to use other String Functions to create a string value, consider using the StringConcatenator (Advanced Mode) or the Text Editor for parameter fields in the AttributeCreator or AttributeManager etc.
Takashi,

 

"Contains RegEx" is a maths operator available in numerous Transformers eg Tester Transformer. I was investigating whether it was possible to use this within the Expression Evaluator. If available it would return, not the actual match but a true or false (1 or 0) to indicate that a match had been made.

 

If not possible - no problem. The same result can be achieved - but >1 Transformer is required.

 

..............

 

I think this would be a really useful addition to the Expression Evaluator (more RegEx functions)

 

.............

 

Thanks once again for all your replies - really useful

 

............

 

Regards

 

Howard L'

 

 


Thanks to EVERYONE for all replies

...........

Regards

Howard L'


Takashi,

 

"Contains RegEx" is a maths operator available in numerous Transformers eg Tester Transformer. I was investigating whether it was possible to use this within the Expression Evaluator. If available it would return, not the actual match but a true or false (1 or 0) to indicate that a match had been made.

 

If not possible - no problem. The same result can be achieved - but >1 Transformer is required.

 

..............

 

I think this would be a really useful addition to the Expression Evaluator (more RegEx functions)

 

.............

 

Thanks once again for all your replies - really useful

 

............

 

Regards

 

Howard L'

 

 

You could use an attributecreator with a conditional statement to achieve a 0 or 1 to indicate a match

 

 

 


Takashi,

 

"Contains RegEx" is a maths operator available in numerous Transformers eg Tester Transformer. I was investigating whether it was possible to use this within the Expression Evaluator. If available it would return, not the actual match but a true or false (1 or 0) to indicate that a match had been made.

 

If not possible - no problem. The same result can be achieved - but >1 Transformer is required.

 

..............

 

I think this would be a really useful addition to the Expression Evaluator (more RegEx functions)

 

.............

 

Thanks once again for all your replies - really useful

 

............

 

Regards

 

Howard L'

 

 

@howard_l you could also use the following expression in the expression evaluator to return 1 or 0 depending on match

 

 

@ceil(@FindRegEx(@Value(Category),0e0-9]e0-9])/@StringLength(@Value(Category)))

 

 

I'm curious why you want to go this route rather than using a differnet transformer that would make things more straightforward

 


Reply