Question

Separate a string into parts according to alpha or numeric characters used


Badge +5

I have an identifier attribute which can take different forms.

All contain a number, like 985 or B985 or 985a

Some are preceded by a capital letter like B985

Some are followed by a smallcaps letter or the character "*" like 985b or 985*

 

I want

  • the capital letters at the beginning of the string to go into attribute PREFIX
  • the numeric to go into attribute NUMBER
  • the smallcaps letter or the * to go into attribute SUFFIX

 

I imagine using regex is the way. I have got the job partly done with a series of StringSearchers but I'd like to have advice from someone with experience.

 

Thanks in advance !

 

 


2 replies

Badge +2

@tim_bkr​  You're probably on the right path with a regular expression in StringSearcher. Something like:

([a-zA-Z]{0,1})([0-9]+)([a-zA-Z\*]{0,1})

Go to regexr.com to learn how that expression works.

The trick is on the StringSearch under Advanced use the Subexpression Matches List Name:

dialogI've attached an example workspace (FME2021.0).

       

Badge +5

Waw, brilliant !

Thanks a ton !

Reply