Are you in the loop? Keep up with the latest by making sure you're subscribed to Community Announcements. Just click Watch and select Articles.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

ScriptRunner Cloud: String replace method

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 Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Nov 21, 2023 • edited

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 Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Nov 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!

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
Site Admin
TAGS
AUG Leaders

Atlassian Community Events