Skip to main content
Question

String Function like StringSearcher RegExp


Forum|alt.badge.img

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

takashi
Contributor
Forum|alt.badge.img+19
  • Contributor
  • August 29, 2017

Hi @hendrik, try this expression.

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

Forum|alt.badge.img
  • Author
  • August 29, 2017
takashi wrote:

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?


takashi
Contributor
Forum|alt.badge.img+19
  • Contributor
  • August 29, 2017
hendrik wrote:

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).

 


Forum|alt.badge.img
  • Author
  • August 29, 2017
hendrik wrote:

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. ;-)

 


ebygomm
Influencer
Forum|alt.badge.img+31
  • Influencer
  • August 29, 2017
hendrik wrote:
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

 

 


takashi
Contributor
Forum|alt.badge.img+19
  • Contributor
  • August 29, 2017
hendrik wrote:

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

 

 


Forum|alt.badge.img
  • Author
  • August 29, 2017
takashi wrote:
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.

 


takashi
Contributor
Forum|alt.badge.img+19
  • Contributor
  • August 29, 2017
hendrik wrote:

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


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings