正規表現に一致する列名のセルの値をMapとして取得します。

@param regex
列名に一致させる正規表現
@param groupIdx
列名の中から抜き出しMapのキーとするグループの番号
@return 正規表現に一致する列名のセルの値
@see Matcher#group(int)
968249
public Map<String, String> getCellValuesAsMap(String regex, int groupIdx,
            List<ReplacePattern> replaces) {
        Map<String, String> map = new TreeMap<String, String>();

        Pattern pattern = Pattern.compile(regex);
        for (Entry<String, String> entry : getData().entrySet()) {
            Matcher matcher = pattern.matcher(entry.getKey());

            if (matcher.matches()) {
                String value = value(entry.getValue(), replaces);
                map.put(matcher.group(groupIdx), value);
            }
        }
        return map;
    }
1222293
function isGroupResult(item) {
  log.trace('isGroupResult(%j)', item);

  if (! item) return(false);
  if (item.groupType) return(true);
  if (item.objectCategory) {
    re.isGroupResult.lastIndex = 0; // Reset the regular expression
    return(re.isGroupResult.test(item.objectCategory));
  }
  if ((item.objectClass) && (item.objectClass.length > 0)) {
    return(_.any(item.objectClass, function(c) { return(c.toLowerCase() === 'group'); }));
  }
  return(false);
}
480847
public static List<String> getAllGroups(Pattern pattern, CharSequence content, boolean withGroup0) {
		if (null == content || null == pattern) {
			return null;
		}

		ArrayList<String> result = new ArrayList<>();
		final Matcher matcher = pattern.matcher(content);
		if (matcher.find()) {
			final int startGroup = withGroup0 ? 0 : 1;
			final int groupCount = matcher.groupCount();
			for (int i = startGroup; i <= groupCount; i++) {
				result.add(matcher.group(i));
			}
		}
		return result;
	}
916197
public static <T extends Collection<String>> T findAll(String regex, CharSequence content, int group, T collection) {
		if (null == regex) {
			return collection;
		}

		return findAll(Pattern.compile(regex, Pattern.DOTALL), content, group, collection);
	}
385758
function createNamedRegex(regexp, flags) {

    if (typeof regexp === "boolean") {
      // options parameter
      if (regexp === false) {
        cache = undefined;
      } else if (!cache) {
        cache = {};
      }
      return;
    }

    if (typeof regexp !== "string") {
      // parameter is regexp literal
      flags = (regexp.global ? "g" : "") +
        (regexp.multiline ? "m" : "") +
        (regexp.ignoreCase ? "i" : "");
      regexp = regexp.source;
    }

    var info = cache ? (cache[regexp] || (cache[regexp] = parseRegex(regexp))) : parseRegex(regexp);
    var regex = new RegExp(info.regexText, flags);

    regex.groupsIndices = info.mapper;

    function extendMatched(matched) {
      var mapper = info.mapper;
      /**
      * Returns value for group name or undefined. If same group name was defined multiple time, it returns first not undefined value.
      * If all is set to true, then it returns array of all matched values.
      */
      matched.group = function (name, all) {
        var indices = mapper[name];
        if (typeof indices === "number") {
          // name group is defined only once
          return matched[indices];
        } else if (all) {
          // name group is defined multiple time and because all is true, return array of all matched values
          return indices.map(function (v) { return matched[v]; });
        } else if (indices) {
          // name group is defined multiple time and because all is false, return first not undefined matched value
          for (var i = 0; i < indices.length; ++i) {
            var value = matched[indices[i]];
            if (value !== undefined) {
              return value;
            }
          }
        }
        return undefined;
      };
      var cachedGroups, cachedGroupsAll;
      matched.groups = function (all) {
        var cg = all ? cachedGroupsAll : cachedGroups;
        if (cg) {
          return cg;
        }
        cg = {};
        for (var name in mapper) {
          cg[name] = matched.group(name, all);
        }
        return all ? cachedGroupsAll = cg : cachedGroups = cg;
      };
      return matched;
    }

    regex.exec = function (text) {
      var matched = RegExp.prototype.exec.call(this, text);
      if (matched) {
        extendMatched(matched);
      }
      return matched;
    }
    regex.execGroups = function (text, all) {
      var matched = this.exec(text);
      if (!matched) {
        return null;
      }
      return matched.groups(all);
    }

    regex.replace = function (text, replacement) {
      if (typeof replacement === "function") {
        return text.replace(regex, function () {
          var matched = Array.prototype.slice.call(arguments, 0, arguments.length - 2);
          extendMatched(matched);
          return replacement.apply(matched, arguments);
        });
      } else {
        var replacementText = parseReplacement(replacement, this.groupsIndices);
        return text.replace(this, replacementText);
      }
    }
    return regex;
  }
1358060
@Deprecated
  public String[] getTableNames(String regex) throws IOException {
    TableName[] tableNames = listTableNames(regex);
    String[] tableIds = new String[tableNames.length];
    for (int i = 0; i < tableNames.length; i++) {
      tableIds[i] = tableNames[i].getNameAsString();
    }
    return tableIds;
  }
630530
String regExpGroupName(String pkgName) {
        for (int j = 0; j < sortedRegExpList.size(); j++) {
            String regexp = sortedRegExpList.get(j);
            if (pkgName.startsWith(regexp)) {
                return regExpGroupMap.get(regexp);
            }
        }
        return null;
    }
132252
protected final String groupKey(CDXLine line) {
		String timestamp = line.getTimestamp();
		return timestamp.substring(0,
			Math.min(timestampDedupLength, timestamp.length()));
	}
1204256
def regex_match(txt, rgx, ignorecase=False, multiline=False):
    '''
    
    '''
    flag = 0
    if ignorecase:
        flag |= re.I
    if multiline:
        flag |= re.M
    obj = re.match(rgx, txt, flag)
    if not obj:
        return
    return obj.groups()
698726
private static int parseGroupId(char[] data, int i, int end, Term term, HashMap<String, Integer> gmap, char closer) throws PatternSyntaxException {
        int id;
        int nstart = i;
        if (Character.isDigit(data[i])) {
            while (Character.isDigit(data[i])) {
                i++;
                if (i == end) throw new PatternSyntaxException("group_id expected");
            }
            id = makeNumber(nstart, i, data);
        } else {
            while (Category.IdentifierPart.contains(data[i])) {
                i++;
                if (i == end) throw new PatternSyntaxException("group_id expected");
            }
            String s = new String(data, nstart, i - nstart);
            Integer no = gmap.get(s);
            if (no == null) throw new PatternSyntaxException("backreference to unknown group: " + s);
            id = no;
        }
        while (Category.Space.contains(data[i])) {
            i++;
            if (i == end) throw new PatternSyntaxException("'" + closer + "' expected");
        }

        int c = data[i++];

        if (c != closer) throw new PatternSyntaxException("'" + closer + "' expected");

        term.memreg = id;
        return i;
    }
375696
@VisibleForTesting
    Map<QName, List<String>> getGroups(final String value) {
        final Map<QName, List<String>> res = new HashMap<>();

        final StringBuilder buf = new StringBuilder();
        int previousEnd = 0;
        final Matcher m = groupPattern.matcher(value);
        while(m.find()) {
            buf.append(value.subSequence(previousEnd, m.start()));
            final String v = m.group(2);
            if (!v.trim().isEmpty()) {
                final QName k = QName.valueOf(m.group(1));
                if (res.containsKey(k)) {
                    final List<String> l = new ArrayList<>(res.get(k));
                    l.addAll(Arrays.asList(v.trim().split("\\s+")));
                    res.put(k, l);
                } else {
                    res.put(k, Arrays.asList(v.trim().split("\\s+")));
                }
            }
            previousEnd = m.end();
        }
        buf.append(value.substring(previousEnd));
        if (!buf.toString().trim().isEmpty()) {
            res.put(null, Arrays.asList(buf.toString().trim().split("\\s+")));
        }
        return res;
    }
79538
public HString findPattern(@NonNull Pattern regex) {
      Matcher m = matcher(regex);
      if (m.find()) {
         return union(substring(m.start(), m.end()).tokens());
      }
      return Fragments.empty(document());
   }
1206616
public ParameterBuilder matching(String regex) {
        Validate.notNull(regex, "regex is required");
        this.pattern = Pattern.compile(regex);
        return this;
    }
1156889
public static String extractRegexGroup(String fromContent, String regex) throws Exception {
        return extractRegexGroup(fromContent, regex, 1);
    }
234839
public static String extractRegexGroup(String fromContent, String regex, int groupNumber) throws Exception {
        if (regex == null) {
            throw new Exception("Cannot extract regex group because the provided regular expression is null.");
        }
        Pattern expectedPattern = Pattern.compile(regex);
        return extractRegexGroup(fromContent, expectedPattern, groupNumber);
    }
761211
public String[] match(String value) {
        if (value == null) {
            return null;
        }
        for (Pattern pattern : patterns) {
            Matcher matcher = pattern.matcher(value);
            if (matcher.matches()) {
                int count = matcher.groupCount();
                String[] groups = new String[count];
                for (int j = 0; j < count; j++) {
                    groups[j] = matcher.group(j + 1);
                }
                return groups;
            }
        }
        return null;
    }
296305
public Stream<HString> findAllPatterns(@NonNull TokenRegex regex) {
      return Streams.asStream(new Iterator<HString>() {
         TokenMatcher m = regex.matcher(HString.this);
         HString nextMatch = null;

         private boolean advance() {
            if (nextMatch == null && m.find()) {
               nextMatch = m.group();
            }
            return nextMatch != null;
         }

         @Override
         public boolean hasNext() {
            return advance();
         }

         @Override
         public HString next() {
            if (!advance()) {
               throw new NoSuchElementException();
            }
            HString toReturn = nextMatch;
            nextMatch = null;
            return toReturn;
         }
      });
   }