How to remove the first occurrence of a character from a Smart Value string?

Doug Shapiro March 5, 2021

Hi. I have a variable in a Jira Automation Rule that holds the contents of a calculation. I would like to remove the number 1 if it's the very first character in the string.  Lets say my variable is "Score". I have been able to get this to work for me:

{{Score.remove("1")}}

I found this example in: https://support.atlassian.com/jira-software-cloud/docs/smart-values-text-fields/

So, for example if "Score" = 108, after the above string removal, it becomes "08" The problem is, if Score=101, I will get a result of 0 since both occurrences of "1" are removed. I only want to remove the first one.

Looking at the String Utils mentioned in the above article, I tried to use this form:
{{Score.Startremove("1")}}
but unfortunately it isn't working and the result is an empty string. I think I need to include another parameter to tell it to just return the source string if the first character is not "1" but I can't figure out how to format that.

Can anyone help?

1 answer

1 accepted

2 votes
Answer accepted
Martin Bayer _MoroSystems_ s_r_o__
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 5, 2021

Hi @Doug Shapiro I think you can use replaceAll function (it works with regular expressions). It could be something like:

  • {{Score.replaceAll("(^1)","")}}
Doug Shapiro March 5, 2021

Thank you very much @Martin Bayer _MoroSystems_ s_r_o__ - this seems to be working! I was concerned by the nomenclature "replaceAll" worried it would remove all occurrences of "1" and I would have the same problem I described but I tested the case of "101" and the result was "01" which is exactly what I wanted.

So, if you don't mind, I'm just trying to get better at this stuff and understand how this works - what keeps this string operation from removing all occurrences of the specified character? I thought it might have been the use of the caret but I tested without the caret and it still worked! So, what does that caret do?

Also, do you happen to know if .Startremove is supported and if so how I would have used it? That said, I'm delighted to use the .replaceAll and understand a bit more about how it works. Thanks again!!!

Martin Bayer _MoroSystems_ s_r_o__
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 5, 2021

Hi @Doug Shapiro , sure, let's explain :)

Doug Shapiro March 5, 2021

@Martin Bayer _MoroSystems_ s_r_o__ Thanks for explaining all of this including confirming what the caret does. I clearly messed up my test without the caret. I  just retested without the caret and as you say, without the caret, it did in fact replace all occurrences! So, "101" became "0". Thanks so much for helping me knock down this wall so I could get this string manipulation working the way I needed!

Best regards,
Doug

Martin Bayer _MoroSystems_ s_r_o__
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 5, 2021

@Doug Shapiro you're welcome, it is always pleasure to help someone who provide detailed information and asks understandable questions :)

Suggest an answer

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

Atlassian Community Events