Overview
This Plug-in exposes Java Regular Expression string manipulation capabilities as Appian Functions. Very useful for validation rules and data manipulation on interactive SAIL forms.
Key Features & Functionality
Datatypes provided:
Regex Flags supported:
Functions provided:
Chris,
I really really need the group captures from regexSearch(). My client doesn't seem to have an agreement to develop & install plugins to their cloud instances.
I was wondering if you could make the necessary changes to your plugin code and get it into marketplace. I fashioned it with what you had already implemented.
First, I created RegexHelperFunctionsGroup.java. It's based off of your RegexHelperFunctions.java. I added the ability to append the captured groups text using "||GRP=>" so the result of a regex search can be easily split() into the matched string, then followed by any captured groups.
What this will mean, you'll need to copy RegexSearch.java to RegexSearchGroup.java and have that call RegexHelperFunctionsGroup.java's Search() instead of RegexHelperFunctions.java's Search() method.
Is this something that can be done asap? Thanks.
RegexHelperFunctionsGroup.java
package com.appiancorp.plugins.regexfunctions.functions;
import java.util.ArrayList;import java.util.List;import java.util.regex.Matcher;import java.util.regex.Pattern;
import com.appiancorp.plugins.regexfunctions.pojos.RegexMatch;
public class RegexHelperFunctionsGroup {
public RegexMatch[] Search(String pattern, String searchString, String regexFlags) { int flags = 0; boolean returnAfterFirst = true; for (int i = 0; i < regexFlags.length(); i++) { switch (regexFlags.charAt(i)) { case 'i': flags = flags | Pattern.CASE_INSENSITIVE; break; case 'm': flags = flags | Pattern.MULTILINE; break; case 's': flags = flags | Pattern.DOTALL; break; case 'u': flags = flags | Pattern.UNICODE_CASE; break; case 'x': flags = flags | Pattern.COMMENTS; break; case 'd': flags = flags | Pattern.UNIX_LINES; break; case 'g': returnAfterFirst = false; break; } } Pattern p = Pattern.compile(pattern, flags); Matcher m = p.matcher(searchString); StringBuffer captures = new StringBuffer(); List<RegexMatchGroup> foundList = new ArrayList<RegexMatchGroup>(); while (m.find()) { captures.delete(0, captures.length()); for (int i = 1; i <= m.groupCount(); i++) { captures.append("||GRP=>" + m.group(i)); } foundList.add(new RegexMatchGroup(m.group() + ((captures.length() > 0) ? captures : null), m.start(), m.end())); /* If we only wanted the first instance, return after finding it */ if (returnAfterFirst) break; } return foundList.toArray(new RegexMatchGroup[foundList.size()]); } }
Hi briank0009,
I've submitted a new version of the plugin that extends the group functionality to the existing search function. You should see it become available over the next few days. In the new version, there's a new optional boolean (defaults to false) parameter at the end of regexSearch for returning the groupings, when it's true it'll return a groups: [{ match: string, startPosition, endPosition}, ...etc ] list within the existing structure.
Thanks.
Awesome. Looking forward to it. Thanks.