本文整理匯總了Java中java.util.regex.Matcher.reset方法的典型用法代碼示例。如果您正苦於以下問題:Java Matcher.reset方法的具體用法?Java Matcher.reset怎麽用?Java Matcher.reset使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.regex.Matcher
的用法示例。
在下文中一共展示了Matcher.reset方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: filterAppPaths
import java.util.regex.Matcher; //導入方法依賴的package包/類
/**
* Filter the list of application file paths to remove those that match the
* regular expression defined by {@link Host#getDeployIgnore()}.
*
* @param unfilteredAppPaths
* The list of application paths to filter
*
* @return The filtered list of application paths
*/
protected String[] filterAppPaths(String[] unfilteredAppPaths) {
Pattern filter = host.getDeployIgnorePattern();
if (filter == null || unfilteredAppPaths == null) {
return unfilteredAppPaths;
}
List<String> filteredList = new ArrayList<String>();
Matcher matcher = null;
for (String appPath : unfilteredAppPaths) {
if (matcher == null) {
matcher = filter.matcher(appPath);
} else {
matcher.reset(appPath);
}
if (matcher.matches()) {
if (log.isDebugEnabled()) {
log.debug(sm.getString("hostConfig.ignorePath", appPath));
}
} else {
filteredList.add(appPath);
}
}
return filteredList.toArray(new String[filteredList.size()]);
}
示例2: filterAppPaths
import java.util.regex.Matcher; //導入方法依賴的package包/類
/**
* Filter the list of application file paths to remove those that match
* the regular expression defined by {@link Host#getDeployIgnore()}.
*
* @param unfilteredAppPaths The list of application paths to filter
*
* @return The filtered list of application paths
*/
protected String[] filterAppPaths(String[] unfilteredAppPaths) {
Pattern filter = host.getDeployIgnorePattern();//null
if (filter == null || unfilteredAppPaths == null) {
return unfilteredAppPaths;
}
List<String> filteredList = new ArrayList<String>();
Matcher matcher = null;
for (String appPath : unfilteredAppPaths) {
if (matcher == null) {
matcher = filter.matcher(appPath);
} else {
matcher.reset(appPath);
}
if (matcher.matches()) {
if (log.isDebugEnabled()) {
log.debug(sm.getString("hostConfig.ignorePath", appPath));
}
} else {
filteredList.add(appPath);
}
}
return filteredList.toArray(new String[filteredList.size()]);
}
示例3: buildLineOffsets
import java.util.regex.Matcher; //導入方法依賴的package包/類
/**
* Build an array giving the starting character offset of each line in
* the document. The HTML parser only reports event positions as line
* and column numbers, so we need this information to be able to
* correctly infer the repositioning information.
*/
private int[] buildLineOffsets(String docContent) {
Matcher m = afterNewlinePattern.matcher(docContent);
// we have to scan the text twice, first to determine how many lines
// there are (i.e. how long the array needs to be)...
int numMatches = 0;
while(m.find()) {
if(DEBUG) {
System.out.println("found line starting at offset " + m.start());
}
numMatches++;
}
int[] lineOffsets = new int[numMatches];
// ... and then again to populate the array with values.
m.reset();
for(int i = 0; i < lineOffsets.length; i++) {
m.find();
lineOffsets[i] = m.start();
}
return lineOffsets;
}
示例4: parse
import java.util.regex.Matcher; //導入方法依賴的package包/類
/**
* Create a ClobRef based on parsed data from a line of text.
* @param inputString the text-based input data to parse.
* @return a ClobRef to the given data.
*/
public static com.cloudera.sqoop.lib.ClobRef parse(String inputString) {
// If inputString is of the form 'externalLob(lf,%s,%d,%d)', then this is
// an external CLOB stored at the LobFile indicated by '%s' with the next
// two arguments representing its offset and length in the file.
// Otherwise, it is an inline CLOB, which we read as-is.
Matcher m = EXTERNAL_MATCHER.get();
m.reset(inputString);
if (m.matches()) {
// This is a LobFile. Extract the filename, offset and len from the
// matcher.
return new com.cloudera.sqoop.lib.ClobRef(m.group(1),
Long.valueOf(m.group(2)), Long.valueOf(m.group(3)));
} else {
// This is inline CLOB string data.
return new com.cloudera.sqoop.lib.ClobRef(inputString);
}
}
示例5: parse
import java.util.regex.Matcher; //導入方法依賴的package包/類
/**
* Create a BlobRef based on parsed data from a line of text.
* This only operates correctly on external blobs; inline blobs are simply
* returned as null. You should store BLOB data in SequenceFile format
* if reparsing is necessary.
* @param inputString the text-based input data to parse.
* @return a new BlobRef containing a reference to an external BLOB, or
* an empty BlobRef if the data to be parsed is actually inline.
*/
public static com.cloudera.sqoop.lib.BlobRef parse(String inputString) {
// If inputString is of the form 'externalLob(lf,%s,%d,%d)', then this is
// an external BLOB stored at the LobFile indicated by '%s' with the next
// two arguments representing its offset and length in the file.
// Otherwise, it is an inline BLOB, which we don't support parsing of.
Matcher m = org.apache.sqoop.lib.LobRef.EXTERNAL_MATCHER.get();
m.reset(inputString);
if (m.matches()) {
// This is a LobFile. Extract the filename, offset and len from the
// matcher.
return new com.cloudera.sqoop.lib.BlobRef(m.group(1),
Long.valueOf(m.group(2)), Long.valueOf(m.group(3)));
} else {
// This is inline BLOB string data.
LOG.warn(
"Reparsing inline BLOB data is not supported; use SequenceFiles.");
return new com.cloudera.sqoop.lib.BlobRef();
}
}
示例6: getKeyPropertyList
import java.util.regex.Matcher; //導入方法依賴的package包/類
static LinkedHashMap<String, String> getKeyPropertyList(ObjectName mbeanName) {
// Implement a version of ObjectName.getKeyPropertyList that returns the
// properties in the ordered they were added (the ObjectName stores them
// in the order they were added).
LinkedHashMap<String, String> output = new LinkedHashMap<String, String>();
String properties = mbeanName.getKeyPropertyListString();
Matcher match = PROPERTY_PATTERN.matcher(properties);
while (match.lookingAt()) {
output.put(match.group(1), match.group(2));
properties = properties.substring(match.end());
if (properties.startsWith(",")) {
properties = properties.substring(1);
}
match.reset(properties);
}
return output;
}
示例7: findMatches
import java.util.regex.Matcher; //導入方法依賴的package包/類
public static List<Match> findMatches(Matcher matcher, String matchee, IndexType type) {
matcher.reset(matchee);
List<Match> matches = new ArrayList<>();
switch (type) {
case INDEX:
case INDEX_BACKWARDS:
while (matcher.find()) {
matches.add(match(matcher));
}
break;
case CAPTURE_GROUP:
if (matcher.matches()) {
for (int i = 0; i < matcher.groupCount(); i++) {
matches.add(groupMatch(matcher, i));
}
}
break;
default:
throw new UnsupportedOperationException(type.name());
}
return matches;
}
示例8: Highlighter
import java.util.regex.Matcher; //導入方法依賴的package包/類
public Highlighter( String text ) {
String stripped = STRIPPER.matcher( text ).replaceAll( "" );
mask = new boolean[stripped.length()];
Matcher m = HIGHLIGHTER.matcher( stripped );
int pos = 0;
int lastMatch = 0;
while (m.find()) {
pos += (m.start() - lastMatch);
int groupLen = m.group( 1 ).length();
for (int i=pos; i < pos + groupLen; i++) {
mask[i] = true;
}
pos += groupLen;
lastMatch = m.end();
}
m.reset( text );
StringBuffer sb = new StringBuffer();
while (m.find()) {
m.appendReplacement( sb, m.group( 1 ) );
}
m.appendTail( sb );
this.text = sb.toString();
}
示例9: getPropertyValue
import java.util.regex.Matcher; //導入方法依賴的package包/類
protected String getPropertyValue(String key, Set<String> seen, Properties... context) {
String value = null;
for(Properties p : context) {
value = p.getProperty(key);
if(value != null) break;
}
if(value != null) {
Matcher m = PLACEHOLDER.matcher(value);
if(m.find()) {
m.reset();
StringBuffer newValue = new StringBuffer();
while(m.find()) {
String varName = m.group(1);
if(seen.contains(varName)) {
throw new RuntimeException("Property " + varName +
" is circularly defined.");
}
seen.add(varName);
try {
String varValue = getPropertyValue(varName, seen, context);
if(varValue == null) {
varValue = m.group();
}
m.appendReplacement(newValue, Matcher.quoteReplacement(varValue));
} finally {
seen.remove(varName);
}
}
m.appendTail(newValue);
value = newValue.toString();
}
}
return value;
}
示例10: Highlighter
import java.util.regex.Matcher; //導入方法依賴的package包/類
public Highlighter(String text) {
String stripped = STRIPPER.matcher(text).replaceAll("");
mask = new boolean[stripped.length()];
Matcher m = HIGHLIGHTER.matcher(stripped);
int pos = 0;
int lastMatch = 0;
while (m.find()) {
pos += (m.start() - lastMatch);
int groupLen = m.group(1).length();
for (int i = pos; i < pos + groupLen; i++) {
mask[i] = true;
}
pos += groupLen;
lastMatch = m.end();
}
m.reset(text);
StringBuffer sb = new StringBuffer();
while (m.find()) {
m.appendReplacement(sb, m.group(1));
}
m.appendTail(sb);
this.text = sb.toString();
}
示例11: Highlighter
import java.util.regex.Matcher; //導入方法依賴的package包/類
public Highlighter(String text) {
String stripped = STRIPPER.matcher(text).replaceAll("");
mask = new boolean[stripped.length()];
Matcher m = HIGHLIGHTER.matcher(stripped);
int pos = 0;
int lastMatch = 0;
while (m.find()) {
pos += (m.start() - lastMatch);
int groupLen = m.group(1).length();
for (int i = pos; i < pos + groupLen; i++) {
mask[i] = true;
}
pos += groupLen;
lastMatch = m.end();
}
m.reset(text);
StringBuffer sb = new StringBuffer();
while (m.find()) {
m.appendReplacement(sb, m.group(1));
}
m.appendTail(sb);
this.text = sb.toString();
}
示例12: checkFileNames
import java.util.regex.Matcher; //導入方法依賴的package包/類
private void checkFileNames(Collection<String> files) {
Matcher m = IndexFileNames.CODEC_FILE_PATTERN.matcher("");
for (String file : files) {
m.reset(file);
if (!m.matches()) {
throw new IllegalArgumentException("invalid codec filename '" + file + "', must match: " + IndexFileNames.CODEC_FILE_PATTERN.pattern());
}
}
}
示例13: visitMatchingTerms
import java.util.regex.Matcher; //導入方法依賴的package包/類
@Override
public void visitMatchingTerms(
IndexReader reader,
String fieldName,
MatchingTermVisitor mtv) throws IOException
{
int prefixLength = prefix.length();
Terms terms = MultiFields.getTerms(reader, fieldName);
if (terms != null) {
Matcher matcher = pattern.matcher("");
try {
TermsEnum termsEnum = terms.iterator(null);
TermsEnum.SeekStatus status = termsEnum.seekCeil(prefixRef);
BytesRef text;
if (status == TermsEnum.SeekStatus.FOUND) {
text = prefixRef;
} else if (status == TermsEnum.SeekStatus.NOT_FOUND) {
text = termsEnum.term();
} else {
text = null;
}
while(text != null) {
if (text != null && StringHelper.startsWith(text, prefixRef)) {
String textString = text.utf8ToString();
matcher.reset(textString.substring(prefixLength));
if (matcher.matches()) {
mtv.visitMatchingTerm(new Term(fieldName, textString));
}
} else {
break;
}
text = termsEnum.next();
}
} finally {
matcher.reset();
}
}
}
示例14: replaceAll
import java.util.regex.Matcher; //導入方法依賴的package包/類
public static String replaceAll(Matcher matcher, Function<String, String> replacement) {
matcher.reset();
boolean result = matcher.find();
if (result) {
StringBuffer sb = new StringBuffer();
do {
matcher.appendReplacement(sb, replacement.apply(matcher.group()));
result = matcher.find();
} while (result);
matcher.appendTail(sb);
return sb.toString();
}
return getOriginalText(matcher).toString();
}
示例15: searchJSON
import java.util.regex.Matcher; //導入方法依賴的package包/類
private static String searchJSON(String regex, String input){
Matcher m;
if(!jsonmatchers.containsKey(regex))
{
jsonmatchers.put(regex, m=Pattern.compile(regex).matcher(input));
}
else
{
m = jsonmatchers.get(regex);
m.reset(input);
}
m.find();
return m.group(1);
}