Question

String Function like StringSearcher RegExp

  • 29 August 2017
  • 8 replies
  • 6 views

Badge

Hi,

i like to create a new Attribute in the AttributeManager using a string function like the StringSearchers FirstMatch.

Is there anything similar as string function?

e.g.:

Input: 102464, 12345, 123478

Regexp: ^\\d*

RegExp-Match: 102464

Desired output: 102464

Greetings Hendrik


8 replies

Userlevel 2
Badge +17

Hi @hendrik, try this expression.

@ReplaceRegEx(@Value(source),^(\d*).*,\1)
Badge

Hi @hendrik, try this expression.

@ReplaceRegEx(@Value(source),^(\d*).*,\1)

Hi @takashi gerat it's working - but i don't understand.

^(\d*) matches the first digits 

.* the rest of the string

\1 sould be the replacement sting

can you explain it to me?

Userlevel 2
Badge +17

Hi @takashi gerat it's working - but i don't understand.

^(\\d*) matches the first digits

.* the rest of the string

\\1 sould be the replacement sting

can you explain it to me?

That's right. \\1 indicates the substring that matches the first sub regex (i.e. the partial expression surrounded by round parens).

 

The function is equivalent to the StringReplacer (Mode: Replace Regular Expression).

 

Badge

Hi @takashi gerat it's working - but i don't understand.

^(\\d*) matches the first digits

.* the rest of the string

\\1 sould be the replacement sting

can you explain it to me?

Is there any documentation for this feature?

 

This is something i assumed to be part of the FindRegEx function. ;-)

 

Userlevel 1
Badge +10
Is there any documentation for this feature?

 

This is something i assumed to be part of the FindRegEx function. ;-)

 

FindRegEx returns the location of the match, not the match itself

 

 

Userlevel 2
Badge +17

Hi @takashi gerat it's working - but i don't understand.

^(\\d*) matches the first digits

.* the rest of the string

\\1 sould be the replacement sting

can you explain it to me?

See here to learn more about FME String Functions: Workbench String Functions

 

 

Badge
See here to learn more about FME String Functions: Workbench String Functions

 

 

This is the standard help for the string functions the \\1 parameter isn't documented there. Maybe someone @safe will take care about that in the future.

 

Userlevel 2
Badge +17

Hi @takashi gerat it's working - but i don't understand.

^(\\d*) matches the first digits

.* the rest of the string

\\1 sould be the replacement sting

can you explain it to me?

\\1 (numbered backreference) is a standard in regular expressions, is not a standard of FME.

 

Regular-Expressions.Info > Replacement String Tutorial > Numbered Backreferences

 

The Help on the StringReplacer mentions it too.

 

Reply