Source:
private static Map<String, Set<String>> getTagsFromGlobalJobTags(String jobName, final String globalJobTags) { Map<String, Set<String>> tags = new HashMap<>(); List<String> globalJobTagsLines = linesToList(globalJobTags); logger.fine(String.format("The list of Global Job Tags are: %s", globalJobTagsLines)); for (String globalTagsLine : globalJobTagsLines) { List<String> jobInfo = cstrToList(globalTagsLine); if (jobInfo.isEmpty()) { continue; } Pattern jobNamePattern = Pattern.compile(jobInfo.get(0)); Matcher jobNameMatcher = jobNamePattern.matcher(jobName); if (jobNameMatcher.matches()) { for (int i = 1; i < jobInfo.size(); i++) { String[] tagItem = jobInfo.get(i).replaceAll(" ", "").split(":"); if (tagItem.length == 2) { String tagName = tagItem[0]; String tagValue = tagItem[1]; if (Character.toString(tagValue.charAt(0)).equals("$")) { try { tagValue = jobNameMatcher.group(Character.getNumericValue(tagValue.charAt(1))); } catch (IndexOutOfBoundsException e) { logger.fine(String.format( "Specified a capture group that doesn't exist, not applying tag: %s Exception: %s", Arrays.toString(tagItem), e)); } } Set<String> tagValues = tags.containsKey(tagName) ? tags.get(tagName) : new HashSet<String>(); tagValues.add(tagValue.toLowerCase()); tags.put(tagName, tagValues); } else if(tagItem.length == 1) { String tagName = tagItem[0]; Set<String> tagValues = tags.containsKey(tagName) ? tags.get(tagName) : new HashSet<String>(); tagValues.add(""); tags.put(tagName, tagValues); } else { logger.fine(String.format("Ignoring the tag %s. It is empty.", tagItem)); } } } } return tags; }

Target:
private static Map<String, Set<String>> getTagsFromGlobalJobTags(String jobName, final String globalJobTags) { Map<String, Set<String>> tags = new HashMap<>(); List<String> globalJobTagsLines = linesToList(globalJobTags); logger.fine(String.format("The list of Global Job Tags are: %s", globalJobTagsLines)); for (String globalTagsLine : globalJobTagsLines) { List<String> jobInfo = cstrToList(globalTagsLine); if (jobInfo.isEmpty()) { continue; } Pattern jobNamePattern = Pattern.compile(jobInfo.get(0)); Matcher jobNameMatcher = jobNamePattern.matcher(jobName); if (jobNameMatcher.matches()) { for (int i = 1; i < jobInfo.size(); i++) { String[] tagItem = jobInfo.get(i).replaceAll(" ", "").split(":", 2); if (tagItem.length == 2) { String tagName = tagItem[0]; String tagValue = tagItem[1]; if (Character.toString(tagValue.charAt(0)).equals("$")) { try { tagValue = jobNameMatcher.group(Character.getNumericValue(tagValue.charAt(1))); } catch (IndexOutOfBoundsException e) { logger.fine(String.format( "Specified a capture group that doesn't exist, not applying tag: %s Exception: %s", Arrays.toString(tagItem), e)); } } Set<String> tagValues = tags.containsKey(tagName) ? tags.get(tagName) : new HashSet<String>(); tagValues.add(tagValue.toLowerCase()); tags.put(tagName, tagValues); } else if(tagItem.length == 1) { String tagName = tagItem[0]; Set<String> tagValues = tags.containsKey(tagName) ? tags.get(tagName) : new HashSet<String>(); tagValues.add(""); tags.put(tagName, tagValues); } else { logger.fine(String.format("Ignoring the tag %s. It is empty.", tagItem)); } } } } return tags; }