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

Version 1 Next »

Summary

Regular Expressions(Regex) can be complicated to create, however, JEMH does not utilise all of the features that Regex offers as JEMH only uses it is for simple pattern matching. JEMH uses Regex for:

This guide cover how to create simple pattern matches and how to use special characters within Regex.

Pattern Matching

Pattern Matching will search for content that matches the Regex exactly. There are multiple different ways that Regex can extract information from the email. Some ways are:

Matching a Static value

Regex can match a static value which has been entered. For example if you want to match the word “Hello” within a email, the Regex will look like:

Hello

The example content below contains the word “Hello” at the start of the line which will return a match:

Hello world, I am a Example email.

Matching Dynamic values

The values you will look for might not always be a static value and this means that you must utilise character classes as this will allow you to look for a value that is of a certain character type.

This example is looking for a IssueKey that is within the AB project. Regex will dynamically look for the number value this will not always be the same.

\[AB-[0-9]+\]

The example subject below will return a value of [AB-34]:

[AB-34] This is a example subject to show dynamic values

Capture groups

Capture groups are used to retrieve a value from the email body to then be used as a value for a Custom Field. To create a capture group put “( )” around the characters that you are looking to extract.

This example is looking for the words “Foreign Key= “ and if found it is adding the following words into the value of a Custom Field.

Foreign Key= ([a-z].*)

The example email body will return the value of “example value”.

Component= Test
Foreign Key= example value
Issuetype= Bug

Escaping Special characters

To match special characters with a Regex you must use “\” to escape these characters. If you would like to escape “\” you would need to put a “\” before this as well which will make it look like “\\”.

Below is a Regex example that escapes “[ ]” so that it will be included when the value is extracted:

(\[[a-z]+-[0-9]+\])

The example content below will return [tb-53]:

[tb-53] example content for matching with a Special character

Special Characters

Regex uses special characters to perform certain functions. Some Special characters that will help with creating expressions are:

Special character

Function

.

This will match any single character other than a newline

*

This matches zero or more consecutive characters. For example (/ba*) will match “ba” and “baaa” as the expression will match more than one “a” characters.

\

Escape following special character. This will allow special characters to be matched within the email. For example if you are looking for “[abc]” the regex will have to be \[abc\] as this will mean that the regex will also look for “[ ]” as a character.

( )

Used to define a capture group within a regex.

[ ]

This is used to define which Character sets you want to capture. For example ([a-z]) will capture all characters that are a lower case alphabetical character.

{ }

Indicates how many characters the value must have. This can be an exact number or between a certain range.

+

Matches one or more consecutive characters.

  • No labels