Forums

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

Automation: How to extract a specific text from description

CI January 10, 2024

The issue Description is like the one in the example below.

I'd like to extract only Text2 from Device.

Which expression can I use? 

Description :

Date
Text1
 
Device
Text2
Text3

Location
Text4
Text5
Text6

 

I tried substringBetween(Device,Location) but it captures both Text2 and Text3. I want only Text2. Is there any way to capture the line after Device

1 answer

0 votes
Alexis Robert
Community Champion
January 10, 2024

Hi @Creative Ideas , 

 

I would try using a different expression to extract Text2 from your example. Can you try this : 

 

{{issue.Description.substringAfter("Device").trim()}}

 

Let me know if this helps,

 

--Alexis

CI January 10, 2024

Hi @Alexis Robert  - Thanks for your support. But it captures all the text after Device.

Below is the output.
Output.JPG

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.
January 10, 2024

Hi @Creative Ideas -- Welcome to the Atlassian Community!

Adding to Alexis's answer...

Your description appears to contain newlines (line feeds) and so building on the earlier suggestion, the result could be split() and then grab the first result.

For example:

{{issue.description.substringAfter("Device").split("\n").get(0).trim()}}

To learn more about these text and list functions, please review this documentation:

This may also be possible to do in one step with the match() function, using a regular expression.

Kind regards,
Bill

Like # people like this
CI January 10, 2024

@Bill Sheboy @Alexis Robert  - Below script worked. Thank you!

{{issue.description.substringAfter("Device").split("\n").get(0).trim()}} 

 
If possible can you please share the script with match() function.

Suggest an answer

Log in or Sign up to answer