Forums

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

Regex question for ScriptRunner

Hadas July 26, 2022

Is there a way to set regex to change "word" with "phrase" but not if "*word*" is there?

I mean, can we change the 'word' only if it is not part of a bigger word?

 

I want to bold a word so looking for "Expected" to change into "*Expected*" but I don't want to change if the word is already bolded.

Thanks for whoever answers

1 answer

0 votes
Hadas July 26, 2022

@Vikrant Yadav I noticed you understand regex pretty well. Do you know if this is possible or not?

Vikrant Yadav
Community Champion
July 26, 2022

Hi @Hadas  Using following regex you can validate the letter between asterisk *letter* or not.  If *vikrant* is written then it's true otherwise it's false. 

Regex code :- \*.*?\*(?!\.\S)

You can test the code here :- https://regex101.com/

Let me know, if this regex not working as per your expectation. 

 

Thanks

V.Y

Like Hadas likes this
Vikrant Yadav
Community Champion
July 26, 2022

@Hadas  if you using JIRA Cloud, it's better to use Project automation instead of scriptrunner. 

Hadas July 27, 2022

But still I'd need regex there right?

The problem is I don't know how to replace a string if it is does not part of a bigger pattern.

How would you replace the following text in the issue description?

expected: bla bla and Exptected: bla bla

with

Exptected: bla bla and Exptected: bla bla

Vikrant Yadav
Community Champion
July 27, 2022

Hi @Hadas  I am not sure how to validate bold letter using Project automation or Scriptrunner for cloud. I think  Regex not work in your scenario. In this smart values need to create. Let me add Project automation expert in our chat. 

@Bill Sheboy  Can you please us in validating and updating plain letter into Bold letter. 

Hadas July 27, 2022

Some more information:

Trying with Jira automation worked if the word "Expected" appears only once but gave weird results if it appears twice or more so I gave it up.

I use ScriptRunner to get the 'description' field text.

and then replaced "Expected" with "*Expected*". The problem it will also replace if "*Expected*" exists and make it "**Expected**" so I want to exclude "*Expected*"

I can work it around with first replacing "*Expected*" with "Expected" but I thought maybe there is a better way to exclude from within the regex expressions.

Vikrant Yadav
Community Champion
July 27, 2022

Using Regex try to validate if it's *expected* or only expected is present in desc.  If *expected* then no action else change to bold. 

In scriptrunner you are changing html description into text right ?  

You can do the same in project automation convert html desc to text then validate using regex. 

Hadas July 27, 2022

But doing so will result in nothing in case both strings exists right? So the non bolded 'expected' would not change also.

Yes I the 'description' comes as text rather than html. I did not did this on purpose. This is how the get call works I guess.

Vikrant Yadav
Community Champion
July 27, 2022

@Hadas  I am not sure how to get description field value in scriptrunner for jira cloud. If it's an api call then result in json right ? In Json for bold result comes in this format :- 

You can check if contains expected under b":[] then don't make it bold. 

b": [
"bold",
"hold"

]

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.
July 27, 2022

Hi @Hadas  and @Vikrant Yadav 

For automation text replacement, you noted the case of "*Expected*" exists and the search/replace makes it "**Expected**"

In my experience...I find some things in the Java Pattern specification for regular expressions are not supported in the automation rule implementation.  So a work-around for the doubling to "**" is to first use a regular expression search/replace, and then chain to use the plain text replace to remove the extra asterisks (or another regular expression).

Kind regards,
Bill

Like Hadas likes this

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