cancel
Showing results for 
Search instead for 
Did you mean: 

Mapping Help - ReplaceAll Except

former_member210091
Participant
0 Kudos

Hey All,

I have a input string like below:

inputString = "Description[1] Product or Service Code. Description[2] Cost Center Code. Description[3] Profit Center Code....Description[n]".

where n = 1 to 9999

I need outputstring string like below

outputString = "Description[1] Product or Service Code. Cost Center Code. Profit Center Code"


So basically, other than the first Description[1] i need to replace all the occurrences of Description[n] with blank.


Can someone please help me with the UDF on how to achieve this.


Thanks


View Entire Topic
former_member182412
Active Contributor
0 Kudos

Hi Saif,

Use below UDF:

Execution Type: Single Values


public String replace(String input, Container container) throws StreamTransformationException {

  return input.replaceAll("Description\\[[^1]\\]", "");

  }

Test:

Regards,

Praveen.

former_member190293
Active Contributor
0 Kudos

Hi Praveen!

Did you try it with "Description[11]" for example?

I guess it might look like: "Description(?!\\[1\\])\\[[0-9]+\\]".

Regards, Evgeniy.

former_member182412
Active Contributor
0 Kudos

Hi Saif,

Use below UDF:


public String replace(String input, Container container) throws StreamTransformationException {

  return input.replaceAll("Description\\[(?!(1\\b))\\d+\\]", "");

  }

Test:

Regards,

Praveen.

former_member182412
Active Contributor
0 Kudos

Hi Evgeniy,

Good catch, i did not test 11, thanks for pointing this out.

Regards,

Praveen.