Home > Mobile >  Regex expression for specific format
Regex expression for specific format

Time:10-18

Hello everyone sorry maybe is a stupid question but I need a regex expression with the next format:

APP-xxxx and COM-xxxx

But in the same expression. I don’t find if is possible to add “or” in the expression. And not empty (The “x” is a numeric and is allow “xxx” and “xxxx”)

Please help. Thank in advance.

Kind regards.

CodePudding user response:

I have not personally used Jira Workflow Validators, but my best guess as to which feature you are using led me to this documentation page:

JSU Automation Suite for Jira Workflows - Server Version: Regular Expression Check Validator

If you are using the server version, then it appears that the Regular Expression is evaluated by Java, as evidenced by their recommendation to test your regex using a Java Regular Expression Tester. That site also includes some basic documentation as well as many examples.

The expression you would most likely find helpful has already been offered in the comments:

(APP|COM)-\d{3,4}

Which means:

  • (APP|COM) :: APP or COM (case sensitive)
  • - :: A literal - character
  • \d{3,4} :: A digit (\d) repeated 3-4 times

The last part has a few alternatives which you can use depending on preference:

\d is basically the same as [0-9] (match one character from 0 to 9)

\d{3,4} could also be expressed as:

  • \d meaning one or more digits (if you don't care have many digits there are, as long as there's at least one)
  • \d{3,} meaning three or more digits
  • \d\d\d\d? meaning three digits following be a fourth optional digit (the ?)
  • Related