Skip to main content
Solved

How to split an attribute with integer to the first 2 digits

  • September 10, 2019
  • 7 replies
  • 235 views

I have an Attribute with integer values (4 Digits) and have to extract the first two Digits and write them to a new Attribute.

In RegEx I think it is ^\\d\\d. How can I do that in FME?

I tried with ExpressionEvaluator and AttributeSplitter @FindRegEx(@Value(Attributename)^\\d\\d)

but it does not working.

 

Thanks for helping.

 

Best answer by ebygomm

In addition if you wanted to use the regex you could use a stringsearcher with your regex

View original
Did this help you find an answer to your question?

7 replies

takashi
Contributor
Forum|alt.badge.img+19
  • Contributor
  • September 10, 2019

Hi @mewi, there should be some ways, using this math expression with ExpressionEvaluator is also one of them. Assuming that an attribute called "attr" always stores 4 digits integer value.

@int(@Value(attr)/100)

  • Author
  • September 10, 2019

Ou, I didn't see this solution. That's quite easy. Luckily I Need the first 2 Digits and not the last ones :-).Thank you @Takashi!


arnold_bijlsma
Enthusiast
Forum|alt.badge.img+14

FME is not explicit in its data types (i.e. whether it's a number, string or datetime attribute), so you can treat any integer as a string and extract its first two digits by using the SubstringExtractor:

 

Note: @takashi and my solution give the same result if your input value is 4 digits exactly, but they give different results if it's got less than or more than 4 digits!!


ebygomm
Influencer
Forum|alt.badge.img+31
  • Influencer
  • Best Answer
  • September 11, 2019

In addition if you wanted to use the regex you could use a stringsearcher with your regex


  • Author
  • September 12, 2019

Thank you for the additional answers @egomm, @arnold_bijlsma. This is very helpful!


sujitbhunia
Contributor
Forum|alt.badge.img+1
  • Contributor
  • September 11, 2024

If i don’t know the length of Integer Value, then how do i extract the integer value from a Attribute.


bwn
Evangelist
Forum|alt.badge.img+26
  • Evangelist
  • September 11, 2024

I generally use StringReplacer + RegEx Groups that allow you to bracket the part of the text that wish to keep as the output.

As a more generalised version of the above solution.  Can find the first 2 digits of any length string like this.

^(\d{2}).*$

Another variation is if want to find the first 1-3 digits say, for any width string is

^(\d{1,3}).*$

 

In RegEx, you can “call back” return a Group string found with notation like \1 for the first group, \2 for the second group etc.  In FME then for Transformers like StringReplacer in RegEx mode, then the replacement string can be set as “\1”  which will tell the Transformer to return only the characters in the 1st group.

 

Putting this together.  Sample Data:

 

 


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