public String findFirst(String originalStr, String regex) { if (StringUtils.isBlank(originalStr) || StringUtils.isBlank(regex)) { return StringUtils.EMPTY; } PatternMatcher matcher = new Perl5Matcher(); if (matcher.contains(originalStr, patterns.get(regex))) { return StringUtils.trimToEmpty(matcher.getMatch().group(0)); } return StringUtils.EMPTY; } }
public void processMatch(MatchResult match) { PortletWindowId windowId=new PortletWindowId(match.group(1)); // obtain portlet content IPortletWindowManager windowManager=getPortletWindowManager(); IPortletRenderContent content=windowManager.getPortletRenderContent(windowId); String titleString = content.getTitle(); if (logger.isDebugEnabled()) { logger.debug("processMatch() - matched portletWindowId \""+match.group(1)+"\", title=\""+titleString+"\""); } // perform substitution StringBuffer b=this.getContentBuffer(); if(titleString==null) { titleString=DEFAULT_TITLE_PATTERN; } if(b!=null) { b.replace(match.beginOffset(0),match.endOffset(0),titleString); } }
buff.append(body.substring(0, match.beginOffset(2))); final int matchGroups = match.groups(); for (int i = 2; i < matchGroups; i++) sb.append(match.group(i)); if (JiraKeyUtils.isPartOfUrl(body, match.beginOffset(2))) body = body.substring(match.endOffset(matchGroups - 1));
public static List<String> getIssueKeysFromString(String body) { if (isBlank(body)) { return Collections.emptyList(); } final Perl5Util util = new Perl5Util(); //note that we have to create a new match, as MatchResult is not Threadsafe final List<String> result = new ArrayList<String>(); while (util.match(getKeyMatcher().getIssueKeyRegex(), body)) { final MatchResult match = util.getMatch(); // The issue key is composed of the all sub-pattern match // groups after the initial sub pattern match group final int matchGroups = match.groups(); // Check backs from the key to see if it part of the url & URL is ignored if (!getKeyMatcher().isIgnoreUrlWithKey() || !isPartOfUrl(body, match.beginOffset(2))) { result.add(createKeyFromMatchingGroups(matchGroups, match)); } body = body.substring(match.endOffset(matchGroups - 1)); } return Collections.unmodifiableList(result); }
String s; if (log.isDebugEnabled()) { log.debug("match groups " + match.groups() + " " + match.toString()); for (int g = 1; g <= NUM_BASE_GROUPS && g <= match.groups(); g++) { s = match.group(g); if (s != null) { if (log.isDebugEnabled()) { for (int g = NUM_BASE_GROUPS + 1; g <= match.groups(); g++) { s = match.group(g); if (s != null) { if (log.isDebugEnabled()) { log.debug("group " + g + " - " + match.group(g));
private static void split(Collection results, PatternMatcher matcher, Pattern pattern, String input, int limit) { int beginOffset; MatchResult currentResult; PatternMatcherInput pinput; pinput = new PatternMatcherInput(input); beginOffset = 0; while (--limit != 0 && matcher.contains(pinput, pattern)) { currentResult = matcher.getMatch(); results.add(input.substring(beginOffset, currentResult .beginOffset(0))); beginOffset = currentResult.endOffset(0); } results.add(input.substring(beginOffset, input.length())); }
/** * 实现<code>MatchResult</code>接口, 取得group的总数. * * @return group的总数, 包括group0, 也就是整个匹配 */ public int groups() { return result == null ? 0 : result.groups(); }
/** * 实现<code>MatchResult</code>接口, 取得指定group相对于整个字符串的位移量. * * @param group group号, 0代表整个匹配 * @return 指定group相对于整个字符串的位移量, 如果指定group不存在或未匹配, 则返回-1 */ public int beginOffset(int group) { return result == null ? -1 : result.beginOffset(group); }
MatchResult result = matcher.getMatch(); buffer = new StringBuffer(); buffer.append(input.substring(result.beginOffset(0) + result.end(0))); logger.debug("Matched! Invoking match closure..."); expectContext = invokeClosure(regExpMatch, input, result);
/** * 实现<code>MatchResult</code>接口, 取得指定group末尾相对于整个字符串的位移量. * * @param group group号, 0代表整个匹配 * @return 指定group末尾相对于整个字符串的位移量, 如果指定group不存在或未匹配, 则返回-1, 被匹配的字符串长度为0, * 则返回起始位移量 */ public int endOffset(int group) { return result == null ? -1 : result.endOffset(group); }
/** * 实现<code>MatchResult</code>接口, 取得整个匹配的字符串, 相当于<code>group(0)</code>. * * @return 整个匹配的字符串 */ @Override public String toString() { return result == null ? "" : result.toString(); }
/** * For debugging purposes - returns a string shows each match group by * number. * * @return a string shows each match group by number. */ public String getGroupsAsString() { StringBuffer b = new StringBuffer(); for (int i = 1; i <= this.result.groups(); i++) { b.append(i).append(") ").append(this.result.group(i)) .append(System.getProperty("line.separator")); } return b.toString(); }
public void processMatch(MatchResult match) { if (logger.isDebugEnabled()) { logger.debug("processMatch() - matched portletWindowId \""+match.group(1)+"\""); } // obtain id in an object form // TODO: define an interface for id factory, otherwise what's the point of having an interface id, if one can only create a specific implementation? PortletWindowId windowId=new PortletWindowId(match.group(1)); // obtain portlet content IPortletWindowManager windowManager=getPortletWindowManager(); IPortletRenderContent content=windowManager.getPortletRenderContent(windowId); String contentString=""; try { contentString = content.getCharacterOutput(); } catch (UnsupportedEncodingException e) { //TODO: replace by error portlet logger.error("processMatch() - can not translate portlet content to string : windowId = " + windowId, e); } // perform substitution StringBuffer b=this.getContentBuffer(); b.replace(match.beginOffset(0),match.endOffset(0),contentString); }
prevMap = g_state.getVars(); int matchedWhere = result.beginOffset(0); String matchedText = result.toString(); // expect_out(0,string) String copyBuffer = new String(chBuffer, 0, result.endOffset(0) ); for (int j = 1; j <= result.groups(); j++) { String group = result.group(j); groups.add( group );
final int matchGroups = match.groups(); final String key = createKeyFromMatchingGroups(matchGroups, match); final int keyStart = match.beginOffset(2); if (isPartOfUrl(body, keyStart)) boolean isInsideAnchor = util.match("/<a[^>]*>(.*?" + key + ".*?)</a>/", body) && (util.getMatch().beginOffset(0) < keyStart); if (isInsideAnchor) endIndex = util.getMatch().endOffset(0); if (endIndex <= keyStart) endIndex = getUrlEnd(body, match.beginOffset(2)); buff.append(body.substring(0, match.beginOffset(2))); body = body.substring(match.endOffset(matchGroups - 1));
public int groups() { return mr.groups(); }
public int beginOffset(int arg0) { int oo=mr.beginOffset(arg0); if(oo!=-1) { return oo-ld; } else { return oo; } }