Forums

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

indexOf starting at a position

Steve Tedeschi
Contributor
February 8, 2025

Trying to parse user provided content in a table - example

||Property||Value||
|prop1|Value 1|

|prop2|value 2|

eg

||Property||Value||

|Date|2025-02-08|

|Day|Saturday|

|Year|2025|

|Month|February|

|Day|8|

I can use the indexOf to find the property "cells" looking for a way to find the first pipe "|" after "|prop1|"... the first pipe after "|prop2|" etc.

 

1 answer

0 votes
Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 8, 2025

Hi @Steve Tedeschi 

Where are you trying to do this?

For example, if this is with an automation rule you could try using the match() function with a regular expression:

https://confluence.atlassian.com/automation/jira-smart-values-text-fields-993924863.html#Jirasmartvaluestextfields-matchmatch() 

Kind regards,
Bill

Steve Tedeschi
Contributor
February 10, 2025

Thanks for the suggestion - looks promising. Will give it a try and update here.

Steve Tedeschi
Contributor
February 12, 2025

@Bill Sheboy Can you help with syntax to access the array elements? I thought I would add the array index in brackets (e.g., [0]), but am getting the following error:

Error rendering smart-values when executing this rule:

Failed to get value for issue.description.match(".*(|).*")[0]: {{issue.description.match(".*(|).*")[0]}}
Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 12, 2025

Hi @Steve Tedeschi 

For accessing list elements in a rule, use the 0-based get() function:

{{issue.description.match(".*(|).*").get(0)}}

or use the first function to get the 0th one:

{{issue.description.match(".*(|).*").first}}

 

Wouldn't both of those just return the pipe character?

Steve Tedeschi
Contributor
February 13, 2025

@Bill Sheboy - First and foremost thank you for pointing me in the right direction!


Q: Wouldn't both of those just return the pipe character?
A: Correct. I am looking for the contents within the table cells, which I am able to do by replacing match with split.

Updated Description (using single pipes for table headers)
|Property|Value|
|Date|2025-02-08|
|Day|Saturday|
|Year|2025|
|Month|February|
|Day|8|

Here's the output:

issue.description.split("|").get(0) = ' '
issue.description.split("|").get(1) = 'Property'
issue.description.split("|").get(2) = 'Value'
issue.description.split("|").get(3) = '
'
issue.description.split("|").get(4) = 'Date'
issue.description.split("|").get(5) = '2025-02-08'
issue.description.split("|").get(6) = '
'
issue.description.split("|").get(7) = 'Day'
issue.description.split("|").get(8) = 'Saturday'
issue.description.split("|").get(9) = '
'
issue.description.split("|").get(10) = 'Year'

 Not sure why the first array item is empty. Items 3, 6, and 9 are new line characters

Like Bill Sheboy likes this
Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 13, 2025

The first is probably null because the leading character is a delimiter (i.e., pipe).

And, newlines can be problematic for scenarios like this, more so when using match().  If they are causing trouble, perhaps replace them with another known / ignored delimiter.  I often use a double-tilde such as ~~ to get them out of the way, but replaceable back to newlines, as needed, later.

 

Just to confirm, do you have what you need now to parse the data?

Steve Tedeschi
Contributor
February 17, 2025

Yes confirmed. Thanks again for pointing me in the right direction!

 

Like Bill Sheboy likes this

Suggest an answer

Log in or Sign up to answer