Class RegexUtil

java.lang.Object
org.cdlib.mrt.utility.RegexUtil

public class RegexUtil extends Object
 This class contains a set of utilities that were built to emulate some
 of the nicer Perl conversion functions.

 Note that the Regex handling uses RegexCache for caching the compiled form 
 of the regular expression

 Created on January 29, 2004, 12:22 PM
 
Author:
David Loy
  • Constructor Details

    • RegexUtil

      public RegexUtil()
  • Method Details

    • replaceString

      public static String replaceString(String in, String from, String to)
      replace a substring value with another substring value
      Parameters:
      in - - string to have value replace
      from - - current substring value in 'in'
      to - - replacement value for 'from'
      Returns:
      - new string with replaced substrings
    • replacePatternString

      public static String replacePatternString(String inStr, String patternS, String fromValue, String toValue)
      Use from and to values to do a replacement within strings matching the given pattern
      Parameters:
      inStr - string to match
      patternS - pattern to be matched
      fromValue - string to be matched for replacement
      toValue - string used for replacement
      Returns:
      string containing replacements
    • listMatches

      public static String[] listMatches(String inStr, String patternS)
      Return list of multiple matches from single pattern match
      Parameters:
      inStr - string to match
      patternS - pattern to be matched
      Returns:
      list of strings containing the subpattern match
    • substitute

      public static String substitute(String inStr, String patternS, String[] array)
      Based on Perl substitute - constructs a response string using the paranthetical subpatterns
      Parameters:
      inStr - string to match
      patternS - pattern to be matches
      array - contains a set of String values that will be sequentially used to construct the output. The array element may contain a reference to the match substring - so "$1" corresponds to the first matched subpattern
      Returns:
      list of strings containing the subpattern match
    • substitute

      public static String substitute(String inStr, String patternS, String[] array, int flags)
      Based on Perl substitute - constructs a response string using the paranthetical subpatterns
      Parameters:
      inStr - string to match
      patternS - pattern to be matches
      array - contains a set of String values that will be sequentially used to construct the output. The array element may contain a reference to the match substring - so "$1" corresponds to the first matched subpattern
      Returns:
      list of strings containing the subpattern match
    • listPattern

      public static String[] listPattern(String inStr, String patternS)
      Return the subpattern matches for a single pattern
      Parameters:
      inStr - string to match
      patternS - pattern to be matched
      Returns:
      list of strings containing the subpattern match