use of org.apache.oro.text.regex.MatchResult in project tdi-studio-se by Talend.
the class DataMapExpressionParser method parseTableEntryLocations.
public TableEntryLocation[] parseTableEntryLocations(String expression) {
resultList.clear();
if (expression != null) {
matcher.setMultiline(true);
if (patternMatcherInput == null) {
patternMatcherInput = new PatternMatcherInput(expression);
} else {
patternMatcherInput.setInput(expression);
}
recompilePatternIfNecessary(locationPattern);
while (matcher.contains(patternMatcherInput, pattern)) {
MatchResult matchResult = matcher.getMatch();
resultList.add(new TableEntryLocation(matchResult.group(1), matchResult.group(2)));
}
}
return resultList.toArray(new TableEntryLocation[0]);
}
use of org.apache.oro.text.regex.MatchResult in project tdi-studio-se by Talend.
the class DataStringConnection method getAnalyse.
/**
* Method getAnalyse extact serveur, port, sid of stringConnection and check the dbType.
*
* @param stringConnection
* @return string[] { selectionIndex, serveur, port, sid }
*/
public String[] getAnalyse(final String stringConnection) {
Integer selectionIndex = getSelectionIndex();
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
String[] s = { selectionIndex.toString(), "", "", "", "", "" };
String regex = getRegex();
if (stringConnection == "") {
//$NON-NLS-1$
return s;
}
Perl5Compiler compiler = new Perl5Compiler();
Perl5Matcher matcher = new Perl5Matcher();
Pattern pattern = null;
try {
pattern = compiler.compile(regex);
if (matcher.contains(stringConnection, pattern)) {
matcher.matches(stringConnection, pattern);
MatchResult matchResult = matcher.getMatch();
s[0] = selectionIndex.toString();
if (matchResult != null) {
for (int i = 1; i < matchResult.groups(); i++) {
s[i] = matchResult.group(i);
}
}
} else {
// search if another regex corresponding at the string of connection
int i = searchGoodRegex(stringConnection);
if (i != getSelectionIndex()) {
setSelectionIndex(i);
s = getAnalyse(stringConnection);
}
}
} catch (MalformedPatternException e) {
// e.printStackTrace();
ExceptionHandler.process(e);
}
return s;
}
use of org.apache.oro.text.regex.MatchResult in project tdi-studio-se by Talend.
the class DataMapExpressionParserTest method main.
public static void main(String[] args) throws Exception {
Perl5Matcher matcher = new Perl5Matcher();
Perl5Compiler compiler = new Perl5Compiler();
// String PATTERN_STR = "\\s*(\\w+)\\s*(\\.\\s*(\\w+)\\s*)+"; // can't get correct group count.
String PATTERN_STR = "(\\s*(\\w+)\\s*\\.\\s*(\\w+)\\s*\\.\\s*(\\w+)\\s*\\.\\s*(\\w+)\\s*\\.\\s*(\\w+)\\s*)" + "|(\\s*(\\w+)\\s*\\.\\s*(\\w+)\\s*\\.\\s*(\\w+)\\s*\\.\\s*(\\w+)\\s*)" + "|(\\s*(\\w+)\\s*\\.\\s*(\\w+)\\s*\\.\\s*(\\w+)\\s*)" + "|(\\s*(\\w+)\\s*\\.\\s*(\\w+)\\s*)";
String expression = "context. schema. context .table.column";
// String expression = "context.schema.table.column";
// String expression = "schema.table.column";
// String expression = "table.column";
matcher.setMultiline(true);
PatternMatcherInput patternMatcherInput = new PatternMatcherInput(expression);
Pattern pattern = compiler.compile(PATTERN_STR);
while (matcher.contains(patternMatcherInput, pattern)) {
MatchResult matchResult = matcher.getMatch();
System.out.println("group count:" + matchResult.groups());
for (int i = 1; i <= matchResult.groups(); i++) {
System.out.println("group[" + i + "] content:" + matchResult.group(i));
}
}
}
use of org.apache.oro.text.regex.MatchResult in project jmeter by apache.
the class RegexExtractor method initTemplate.
private void initTemplate() {
if (template != null) {
return;
}
// Contains Strings and Integers
List<Object> combined = new ArrayList<>();
String rawTemplate = getTemplate();
PatternMatcher matcher = JMeterUtils.getMatcher();
Pattern templatePattern = // $NON-NLS-1$
JMeterUtils.getPatternCache().getPattern(// $NON-NLS-1$
"\\$(\\d+)\\$", Perl5Compiler.READ_ONLY_MASK & Perl5Compiler.SINGLELINE_MASK);
if (log.isDebugEnabled()) {
log.debug("Pattern = '{}', template = '{}'", templatePattern.getPattern(), rawTemplate);
}
int beginOffset = 0;
MatchResult currentResult;
PatternMatcherInput pinput = new PatternMatcherInput(rawTemplate);
while (matcher.contains(pinput, templatePattern)) {
currentResult = matcher.getMatch();
final int beginMatch = currentResult.beginOffset(0);
if (beginMatch > beginOffset) {
// string is not empty
combined.add(rawTemplate.substring(beginOffset, beginMatch));
}
// add match as Integer
combined.add(Integer.valueOf(currentResult.group(1)));
beginOffset = currentResult.endOffset(0);
}
if (beginOffset < rawTemplate.length()) {
// trailing string is not empty
combined.add(rawTemplate.substring(beginOffset, rawTemplate.length()));
}
if (log.isDebugEnabled()) {
log.debug("Template item count: {}", combined.size());
int i = 0;
for (Object o : combined) {
log.debug("Template item-{}: {} '{}'", i++, o.getClass(), o);
}
}
template = combined;
}
use of org.apache.oro.text.regex.MatchResult in project jmeter by apache.
the class RegexExtractor method processMatches.
private List<MatchResult> processMatches(Pattern pattern, String regex, SampleResult result, int matchNumber, JMeterVariables vars) {
log.debug("Regex = '{}'", regex);
Perl5Matcher matcher = JMeterUtils.getMatcher();
List<MatchResult> matches = new ArrayList<>();
int found = 0;
if (isScopeVariable()) {
String inputString = vars.get(getVariableName());
if (inputString == null) {
if (log.isWarnEnabled()) {
log.warn("No variable '{}' found to process by RegexExtractor '{}', skipping processing", getVariableName(), getName());
}
return Collections.emptyList();
}
matchStrings(matchNumber, matcher, pattern, matches, found, inputString);
} else {
List<SampleResult> sampleList = getSampleList(result);
for (SampleResult sr : sampleList) {
String inputString = getInputString(sr);
found = matchStrings(matchNumber, matcher, pattern, matches, found, inputString);
if (matchNumber > 0 && found == matchNumber) {
// no need to process further
break;
}
}
}
return matches;
}
Aggregations