Skip to main content
Solved

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

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

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

5 replies

pallegama
Contributor
Forum|alt.badge.img+8
  • Contributor
  • 25 replies
  • 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
  • 48 replies
  • 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
  • 1 reply
  • February 22, 2018

Works like a charm,

thank you very much


gio
Contributor
Forum|alt.badge.img+15
  • Contributor
  • 2252 replies
  • 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+18
  • Supporter
  • 1442 replies
  • February 22, 2018

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