This is an automated archive made by the Lemmit Bot.

The original was posted on /r/tasker by /u/aasswwddd on 2025-09-25 12:34:45+00:00.


You can grab the beta link from his comment here. https://www.reddit.com/r/tasker/comments/1np7f3k/comment/ng3sa7b

Joao will probably make a post about this soon, just in case everyone want to give it a go earlier:)

This is way too soon u/joaomgcd! I’ve sent a feature req about two weeks ago, posted here yesterday and here we are now!

I tested this to replicate simple match/regex action and it works! This code will output the result in JSON data.

import java.util.regex.*;
import java.util.*;
import java.lang.reflect.*;
import org.json.JSONObject;
import org.json.JSONArray;

String inputText = "text";
String regexPattern = "t";

Pattern pattern = Pattern.compile(regexPattern, Pattern.MULTILINE);
Matcher matcher = pattern.matcher(inputText);

Map matchInfo = new HashMap();
List allMatches = new ArrayList();

Map groupNames = new HashMap();   // index -> name mapping
boolean java9Api = false;

// --- Try Java 9+ native support ---
try {
    Method namedGroupsMethod = Pattern.class.getDeclaredMethod("namedGroups", new Class[0]);
    namedGroupsMethod.setAccessible(true);
    groupNames = (Map) namedGroupsMethod.invoke(pattern, new Object[0]);
    java9Api = true;
} catch (Throwable t) {
    // Fallback: parse manually
    Pattern ngPattern = Pattern.compile("\\(\\?<([a-zA-Z][a-zA-Z0-9_]*)>");
    Matcher ngMatcher = ngPattern.matcher(regexPattern);
    int idx = 1;
    while (ngMatcher.find()) {
        String name = ngMatcher.group(1);
        groupNames.put(new Integer(idx), name);
        idx++;
    }
}

// --- Iterate matches ---
while (matcher.find()) {
    int totalGroups = matcher.groupCount();

    for (int i = 1; i <= totalGroups; i++) {
        String value = matcher.group(i);
        if (value != null) {
            String name;
            if (groupNames.containsKey(new Integer(i))) {
                name = (String) groupNames.get(new Integer(i));
            } else {
                name = "group" + i;
            }

            if (!matchInfo.containsKey(name)) {
                matchInfo.put(name, new JSONArray());
            }
            ((JSONArray) matchInfo.get(name)).put(value);
        }
    }

    allMatches.add(matcher.group());
}

// Add raw matches
matchInfo.put("matches", new JSONArray(allMatches));

// Convert to JSON string
JSONObject json = new JSONObject(matchInfo);
String result = json.toString(2);

System.out.println(result);
result;