Skip to main content
Solved

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

  • February 22, 2018
  • 5 replies
  • 10 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

Best answer by pallegama

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

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

5 replies

pallegama
Contributor
Forum|alt.badge.img+8
  • Contributor
  • Best Answer
  • February 22, 2018

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


Forum|alt.badge.img
  • February 22, 2018

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

python-string.fmw


  • Author
  • February 22, 2018

Works like a charm,

thank you very much


gio
Contributor
Forum|alt.badge.img+15
  • Contributor
  • February 22, 2018

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.


itay
Supporter
Forum|alt.badge.img+16
  • Supporter
  • February 22, 2018

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


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