Skip to main content
Solved

How to add sting after a specific caracter

  • May 15, 2020
  • 5 replies
  • 29 views

boubcher
Contributor
Forum|alt.badge.img+11

Hello there

I have an attribute with values concatenated, I am looking to add character for each value

 

Before Attributephoto1,photo2,photo3

 

looking to get this after :

 

attributehttp://photo1/text,http://photo2/text,http://photo3/text

Best answer by ebygomm

You can do this with a regular expression in a string replacer

The regular expression (photo\\d+) matches any occurrence of the word photo followed by one or more numbers

The replacement text then replaces the matched value with http:// followed by the matched group \\1 followed by /text

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

ebygomm
Influencer
Forum|alt.badge.img+44
  • Influencer
  • 3427 replies
  • Best Answer
  • May 15, 2020

You can do this with a regular expression in a string replacer

The regular expression (photo\\d+) matches any occurrence of the word photo followed by one or more numbers

The replacement text then replaces the matched value with http:// followed by the matched group \\1 followed by /text


boubcher
Contributor
Forum|alt.badge.img+11
  • Author
  • Contributor
  • 212 replies
  • May 15, 2020

You can do this with a regular expression in a string replacer

The regular expression (photo\\d+) matches any occurrence of the word photo followed by one or more numbers

The replacement text then replaces the matched value with http:// followed by the matched group \\1 followed by /text

@ebygomm

Thanks for your response I am not getting the same results in all feature

let me share the exact value

Before

mdc_photo_mdc_e7669f_cdv_photo_011_1558001156719.jpg,mdc_photo_mdc_0403/textd8_cdv_photo_001_1581000976829.jpg,mdc_photo_mdc_f0f840_cdv_photo_001_1581000976829.jpg,mdc_photo_mdc_2/textecf29_cdv_photo_001_1581000976829.jpg

we should get this

http://mdc_photo_mdc_e7669f_cdv_photo_011_1558001156719.jpg/text,http://mdc_photo_mdc_0403/textd8_cdv_photo_001_1581000976829.jpg/text,http://mdc_photo_mdc_f0f840_cdv_photo_001_1581000976829.jpg/text,http://mdc_photo_mdc_2/textecf29_cdv_photo_001_1581000976829.jpg/text

the expression you shared not giving the right results

as you can see the values are separated by ", "

 


ebygomm
Influencer
Forum|alt.badge.img+44
  • Influencer
  • 3427 replies
  • May 15, 2020

@ebygomm

Thanks for your response I am not getting the same results in all feature 

let me share the exact value 

Before

mdc_photo_mdc_e7669f_cdv_photo_011_1558001156719.jpg,mdc_photo_mdc_0403/textd8_cdv_photo_001_1581000976829.jpg,mdc_photo_mdc_f0f840_cdv_photo_001_1581000976829.jpg,mdc_photo_mdc_2/textecf29_cdv_photo_001_1581000976829.jpg

we should get this 

http://mdc_photo_mdc_e7669f_cdv_photo_011_1558001156719.jpg/text,http://mdc_photo_mdc_0403/textd8_cdv_photo_001_1581000976829.jpg/text,http://mdc_photo_mdc_f0f840_cdv_photo_001_1581000976829.jpg/text,http://mdc_photo_mdc_2/textecf29_cdv_photo_001_1581000976829.jpg/text

the expression you shared not giving the right results  

as you can see the values are separated by  ", "

 

Well no, you need quite a different regular expression for the actual data :-)

I think this regex might work for you, if all your strings start with mdc and end in .jpg

(mdc.*?.jpg)

ebygomm
Influencer
Forum|alt.badge.img+44
  • Influencer
  • 3427 replies
  • May 15, 2020

A python alternative, which may be safer if the image names are not reliably consistent but are always comma separated

import fme
import fmeobjects

def processFeature(feature):
    attrlist = feature.getAttribute('attribute').split(',')
    newlist = ['http://'+i+'/text' for i in attrlist]
    feature.setAttribute("attribute", ','.join(newlist))

You could of course, also split the attribute with the comma, explode the list, append the characters that you need, then rebuild the attribute but it's a bit inefficient


boubcher
Contributor
Forum|alt.badge.img+11
  • Author
  • Contributor
  • 212 replies
  • May 15, 2020

@ebygomm

Thanks so mutch