org.apache.commons.lang3.StringUtils.removePattern()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(9.6k)|赞(0)|评价(0)|浏览(112)

本文整理了Java中org.apache.commons.lang3.StringUtils.removePattern()方法的一些代码示例,展示了StringUtils.removePattern()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。StringUtils.removePattern()方法的具体详情如下:
包路径:org.apache.commons.lang3.StringUtils
类名称:StringUtils
方法名:removePattern

StringUtils.removePattern介绍

[英]Removes each substring of the source String that matches the given regular expression using the DOTALL option.
This call is a null safe equivalent to:

  • source.replaceAll("(?s)" + regex, StringUtils.EMPTY)
  • Pattern.compile(regex, Pattern.DOTALL).matcher(source).replaceAll(StringUtils.EMPTY)

A null reference passed to this method is a no-op.

StringUtils.removePattern(null, *)       = null 
StringUtils.removePattern("any", (String) null)   = "any" 
StringUtils.removePattern("A<__>\n<__>B", "<.*>")  = "AB" 
StringUtils.removePattern("ABCabc123", "[a-z]")    = "ABC123"

[中]使用DOTALL选项删除与给定正则表达式匹配的源字符串的每个子字符串。
此调用是一个空安全等价于:
*来源。replaceAll(“(?s)”+正则表达式,StringUtils。空的)
*模式。编译(regex,Pattern.DOTALL)。匹配器(来源)。replaceAll(StringUtils.EMPTY)
传递给此方法的null引用是no-op。

StringUtils.removePattern(null, *)       = null 
StringUtils.removePattern("any", (String) null)   = "any" 
StringUtils.removePattern("A<__>\n<__>B", "<.*>")  = "AB" 
StringUtils.removePattern("ABCabc123", "[a-z]")    = "ABC123"

代码示例

代码示例来源:origin: org.apache.commons/commons-lang3

@Test
public void testRemovePattern_StringString() {
  assertNull(StringUtils.removePattern(null, ""));
  assertEquals("any", StringUtils.removePattern("any", null));
  assertEquals("", StringUtils.removePattern("", ""));
  assertEquals("", StringUtils.removePattern("", ".*"));
  assertEquals("", StringUtils.removePattern("", ".+"));
  assertEquals("AB", StringUtils.removePattern("A<__>\n<__>B", "<.*>"));
  assertEquals("AB", StringUtils.removePattern("A<__>\\n<__>B", "<.*>"));
  assertEquals("", StringUtils.removePattern("<A>x\\ny</A>", "<A>.*</A>"));
  assertEquals("", StringUtils.removePattern("<A>\nxy\n</A>", "<A>.*</A>"));
  assertEquals("ABC123", StringUtils.removePattern("ABCabc123", "[a-z]"));
}

代码示例来源:origin: virjar/vscrawler

@Override
protected String handle(String input, String second) {
  return StringUtils.removePattern(input, second);
}

代码示例来源:origin: jenkinsci/analysis-core-plugin

String stripRelativePrefix(final String annotationFileName) {
  return StringUtils.removePattern(annotationFileName, ".*(\\.\\.?/)+");
}

代码示例来源:origin: griddynamics/jagger

public static String extractDisplayNameFromGenerated(String generatedDisplayName) {
  if (DISPLAY_NAME_PATTERN.matcher(generatedDisplayName).matches()) {
    return removePattern(generatedDisplayName, " (" + LATENCY_SEC + "|" + ITERATIONS_SAMPLES + "|" + SUCCESS_RATE + ") \\[.*\\]");
  }
  log.warn("Generated display name '{}' doesn't match regexp '{}'. Will return null.", generatedDisplayName, DISPLAY_NAME_REGEXP);
  return null;
}

代码示例来源:origin: Cognifide/knotx

private static String getFormIdentifier(Fragment fragment) {
 return fragment.knots().stream()
   .filter(knot -> knot.startsWith(FRAGMENT_KNOT_PREFIX))
   .map(knot -> StringUtils.removePattern(knot, FRAGMENT_KNOT_PATTERN))
   .map(id -> StringUtils.isBlank(id) ? FORM_DEFAULT_IDENTIFIER : id)
   .findFirst().orElseThrow(() -> {
    LOGGER.error("Could not find action adapter name in fragment [{}].",
      fragment);
    return new NoSuchElementException("Could not find action adapter name");
   });
}

代码示例来源:origin: CityOfNewYork/geoclient

public static String sanitize(String s)
{
  if(s == null || s.isEmpty())
  {
    return s;
  }
  // Remove leading and trailing spaces or punctuation (except for trailing 
   //period characters (eg, N.Y.)
  String clean = StringUtils.removePattern(s,"^(?:\\s|\\p{Punct})+|(?:\\s|[\\p{Punct}&&[^.]])+$");
  // Make sure ampersand is surrounded by spaces but allow double ampersand
  clean = clean.replaceAll("([^\\s&])\\&", "$1 &");
  clean = clean.replaceAll("\\&([^\\s&])", "& $1");
  // Normalize whitespace
  clean = StringUtils.normalizeSpace(clean);
  return clean;
}

代码示例来源:origin: beihaifeiwu/dolphin

public String convert(String actualColumnName) {
 //System.out.println(actualColumnName);
 Matcher matcher = columnPattern.matcher(actualColumnName);
 StringBuilder sb = new StringBuilder();
 while (matcher.find()) {
  String word = matcher.group();
  word = removePattern(word, "[^a-zA-Z]"); //去除word中所有非字母字符
  sb.append(capitalize(word.toLowerCase()));
 }
 String result = sb.toString();
 //System.out.println(result);
 if (isAllUpperCase(result)) { //实际列名全为大写时则全部改为小写
  result = result.toLowerCase();
 } else {
  result = uncapitalize(result);
 }
 //System.out.println(result);
 return result;
}

代码示例来源:origin: org.languagetool/language-de

private boolean ignoreElative(String word) {
 if (StringUtils.startsWithAny(word, "bitter", "dunkel", "erz", "extra", "früh",
   "gemein", "hyper", "lau", "mega", "minder", "stock", "super", "tod", "ultra", "ur")) {
  String lastPart = StringUtils.removePattern(word, "^(bitter|dunkel|erz|extra|früh|gemein|grund|hyper|lau|mega|minder|stock|super|tod|ultra|ur|voll)");
  return !isMisspelled(lastPart);
 }
 return false;
}

代码示例来源:origin: mopemope/meghanada-server

Optional<LocalVariable> createLocalVariable(
  final AccessSymbol accessSymbol, final String returnType) {
 if (returnType.equals("void")) {
  return Optional.of(new LocalVariable(returnType, new ArrayList<>(0)));
 }
 // completion
 final List<String> candidates = new ArrayList<>(4);
 // 1. from type
 final List<String> fromTypes = this.fromType(returnType);
 candidates.addAll(fromTypes);
 // 2. add method or isField name
 final List<String> fromNames = this.fromName(accessSymbol);
 candidates.addAll(fromNames);
 // 3. add returnType initials
 if (returnType.startsWith("java.lang") || ClassNameUtils.isPrimitive(returnType)) {
  final String initial = fromInitial(returnType);
  candidates.add(initial);
 }
 final List<String> results =
   candidates.stream()
     .map(s -> StringUtils.removePattern(s, "[<> ,$.]"))
     .collect(Collectors.toList());
 return Optional.of(new LocalVariable(returnType, results));
}

代码示例来源:origin: mopemope/meghanada-server

private List<String> fromType(final String returnType) {
 Set<String> names = new HashSet<>(4);
 final String simpleName = ClassNameUtils.getSimpleName(returnType);
 final int i = simpleName.indexOf('<');
 if (i > 0) {
  final String gen = simpleName.substring(i);
  final String cls = simpleName.substring(0, i);
  String removed = StringUtils.removePattern(gen, "[<> ,$.]");
  if (JavaVariableCompletion.isPlural(cls)) {
   removed = StringUtils.uncapitalize(English.plural(removed));
  }
  final String[] strings = StringUtils.splitByCharacterTypeCamelCase(removed);
  final List<String> nameList = new ArrayList<>(Arrays.asList(strings));
  this.addName(names, nameList);
  names.add(StringUtils.uncapitalize(removed + StringUtils.capitalize(cls)));
 } else {
  if (!ClassNameUtils.isPrimitive(returnType)) {
   final String n = StringUtils.uncapitalize(simpleName);
   final String[] strings = StringUtils.splitByCharacterTypeCamelCase(n);
   final List<String> nameList = new ArrayList<>(Arrays.asList(strings));
   this.addName(names, nameList);
  }
 }
 return new ArrayList<>(names);
}

代码示例来源:origin: pl.edu.icm.synat/synat-process-common

String cleared = name.getText();
for (String pattern : PATTERNS_TO_REMOVE) {
  cleared = StringUtils.removePattern(cleared, pattern);
final String newEmail = StringUtils.removePattern(email, "E[-]?mail:");
if (!StringUtils.equals(email, newEmail)) {
  Iterator<YAttribute> itr = contributor.getAttributes().iterator();

代码示例来源:origin: iterate-ch/cyberduck

protected PathAttributes toAttributes(final ObjectMetadata metadata) {
    final PathAttributes attributes = new PathAttributes();
    attributes.setSize(Long.valueOf(metadata.getContentLength()));
    final String lastModified = metadata.getLastModified();
    try {
      attributes.setModificationDate(rfc1123DateFormatter.parse(lastModified).getTime());
    }
    catch(InvalidDateException e) {
      log.warn(String.format("%s is not RFC 1123 format %s", lastModified, e.getMessage()));
    }
    if(StringUtils.isNotBlank(metadata.getETag())) {
      final String etag = StringUtils.removePattern(metadata.getETag(), "\"");
      attributes.setETag(etag);
      if(metadata.getMetaData().containsKey(Constants.X_STATIC_LARGE_OBJECT)) {
        // For manifest files, the ETag in the response for a GET or HEAD on the manifest file is the MD5 sum of
        // the concatenated string of ETags for each of the segments in the manifest.
        attributes.setChecksum(Checksum.NONE);
      }
      else {
        attributes.setChecksum(Checksum.parse(etag));
      }
    }
    return attributes;
  }
}

代码示例来源:origin: org.languagetool/language-de

if (StringUtils.startsWithAny(word, "bitter", "dunkel", "erz", "extra", "früh",
 "gemein", "hyper", "lau", "mega", "minder", "stock", "super", "tod", "ultra", "ur")) {
 String lastPart = StringUtils.removePattern(word, "^(bitter|dunkel|erz|extra|früh|gemein|grund|hyper|lau|mega|minder|stock|super|tod|ultra|ur|voll)");
 if (lastPart.length() > 1) {
  String firstPart = StringUtils.removeEnd(word, lastPart);

代码示例来源:origin: FINRAOS/herd

whitelistTag = StringUtils.removePattern(whitelistTag, "[^\\{IsAlphabetic}]");

代码示例来源:origin: org.finra.herd/herd-core

whitelistTag = StringUtils.removePattern(whitelistTag, "[^\\{IsAlphabetic}]");

相关文章

微信公众号

最新文章

更多

StringUtils类方法