Skip to main content
Solved

How to add sting after a specific caracter


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

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

5 replies

ebygomm
Influencer
Forum|alt.badge.img+31
  • Influencer
  • 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
  • May 15, 2020
ebygomm wrote:

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+31
  • Influencer
  • May 15, 2020
boubcher wrote:

@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+31
  • Influencer
  • 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
  • May 15, 2020

@ebygomm

Thanks so mutch

 


Reply


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