Solved

How to return a variable amount of characters in the middle of a string

  • 22 February 2018
  • 5 replies
  • 2 views

I need to extract a variable amount of characters from a string and would like some help.

I have an attribute in the following format:

id-Structure-1.1.13.1.6.1

I need to extract the first 4 numbers (1.1.13.1)

Where it's get tricky, is that each number can have a value that may varies between 1 and 6000

so it's possible to see "id-Structure-1.5474.768.322.22.12" where I'd like to extract (1.5474.768.322)

Any help would be much appreciate

thanks

icon

Best answer by pallegama 22 February 2018, 02:07

View original

5 replies

Badge

Hi @hugo_pspc,

Regular Expression [0-9]\\d*.\\d*.\\d*.\\d* in StringSearcher transformer works for me.

Please see the attached sample workspace.

stringsearcher 

string-seracher.fmw

Badge

It also can be done in python, A few more lines of code but does give a lot more options later

python-string.fmw

Works like a charm,

thank you very much

Badge +3

is [0-9] not same as \\d ?.

Stringsearcher can also be used in advanced mode.

Use

\\W*(\\d+)\\w* or \\.*(\\d+)\\.*

and set SM (and for the all match if needed AM). SM.part(0)-SM.part(3) is what your looking for.

Badge +16

Alternatively you can replace/erase "id-Structure-" and any points with a StringReplacer......

Reply