Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

ScriptRunner Cloud: String replace method

Benjamin Dombrowsky _D4Digital_ November 21, 2023

Hi,

I am currently trying to remove a part of a string in ScriptRunner.

The string looks like this:

foobar (DASD)

Everything between and including the brackets should be removed. I have already tried various methods, but so far without success.

Can someone provide me with a suitable method?

Thank you very much!

2 answers

2 accepted

1 vote
Answer accepted
Kristian Walker _Adaptavist_
Community Champion
November 21, 2023

Hi Benjamin,

As ScriptRunner for Jira Cloud runs Groovy, you should use the replaceAll method as documented here.

Using this, you would assign your string to a variable, and then you could call replace all on it using a regular expression to remove everything inside and including the brackets, as shown in the example here.

 

I hope this helps.
Regards,
Kristian
1 vote
Answer accepted
Aron Gombas _Midori_
Community Champion
November 21, 2023

ScriptRunner is using the Groovy language, therefore your question translates to: how can I remove the suffix including the space charater?

Here is the answer, although it removes the suffix including a dot character: https://stackoverflow.com/questions/34321526/groovy-way-to-remove-file-extension

You can easily change the '.' to ' ' and bingo!

Benjamin Dombrowsky _D4Digital_ November 21, 2023

thx

def customFieldValueCleaned = customFieldValue.take(customFieldValue.lastIndexOf('('))

does exactly what I want! 

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events