Example scripts
To homepage
Jira

Use Regex to Find Email Addresses in a String and Find the User
App in script

ScriptRunner For Jira
by Adaptavist
Compatibility

Jira (8.14 - 9.5)

ScriptRunner For Jira (7.7.0)
Language |
groovy
import java.util.regex.Pattern
import com.atlassian.jira.component.ComponentAccessor
//Define the UserSearchService, which we will use to find the User from the Email Address
def userSearchService = ComponentAccessor.userSearchService
//Define the Regex to find the Email Addresses
def regex = "([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\\.[a-zA-Z0-9_-]+)"
//Define a String to search through
def searchQuery = "this is the email: example@email.com, anotherExample@email.com"
//Define the Pattern with the Regex, and the Matcher with the searchQuery
def pattern = Pattern.compile(regex, Pattern.MULTILINE)
def matcher = pattern.matcher(searchQuery)
//Using each, iterate through the Matcher's result
matcher.each {
//Observe the Email Address found
log.warn matcher.group(0)
//Use the UserSearchService to find the User by Email
def userFoundByEmail = userSearchService.findUsersByEmail( matcher.group(0) )
//Observe the User found - if this returns an empty List, no User was found
log.warn userFoundByEmail
}
Having an issue with this script?
Report it here