Skip to end of banner
Go to start of banner

How to use regular expressions

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 11 Next »

Description

A number of add-ons provide advanced features that require the use of regular expressions for pattern matching. Generally, just a simple understanding of regular expressions and a few examples are enough to get by for most use cases. This will just give a few simple examples to get started. Use the references for more advanced information.

Regex for workflow conditions

For JIRA workflow functions using regex expressions to condition whether the post function should continue processing, a blank pattern means that condition processing is not done and processing should continue.

Key tips

  1. Dot or period (.) is a special regex character. If you really want to match on it, you need to escape it with a backslash: \.
  2. Don't be confused with generic pattern matching used for file systems for instance. On a file system, *.png means all files ending with .png. That is an illegal regex expression. For regex you need: .*\.png. Or to simplify: .*png which will find all files ending in png (not necessarily ending in an extension of png).
  3. Regex is case sensitive by default. In most cases, use the case insensitive flag: (?i). See one of the examples below.

References

Simple examples

Value
Regex
Matches
Demonstrates
ABCA.C(tick). matches any single character
ABCA.*(tick)

* indicates 0 or more

ABC.*C(tick) 
A.BA\.B(tick)Escape special regex characters with backslash if necessary
ABCAB*(error)

Regex is NOT generic matching (smile)

ABCA.+(tick)+ indicates 1 or more
ABCABC.+(error) 
ABCABC.*(tick) 
ABCDABC.*(tick) 
ABC[ABCD](tick)[ ] indicates a class of characters
ABC[ABZ] (error) 
ABC8[A-Z0-9](tick)

- indicates a range of characters

ABC[AB^C](error)^ in a class means NOT the following character
ABCDEF|ABC(tick)| indicates OR
image.png.*png|.*jpg(tick) 
image.jpg.*png|.*jpg(tick) 
image.JPG.*png|.*jpg(error)defaults to case sensitive matching
image.JPG(?i).*png|.*jpg(tick)

(?i) indicates case insensitive matching

ABAB(AB)+(tick)() indicates a grouping
ABCD(AB)+(error) 
112233\d+(tick)\d for digits
A BA\s*B(tick)\s for whitespace
ABC\S*(tick)\S for non whitespace
 \S+(error)Value must have at least 1 non whitespace character
A\S+(tick) 
XYZ,ABC,UVW.*\bABC\b.*(tick)Finding words in a comma or blank separated list using word boundaries
XYZ,ABCD,UVW.*\bABC\b.*(error) 

 

Content with regex label


  • No labels