net.sf.okapi.common

## Class RegexUtil

- java.lang.Object
- - net.sf.okapi.common.RegexUtil

-     public class RegexUtil
      extends java.lang.Object

  Collection of helper function for working with regular expressions.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `RegexUtil()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static boolean` | `contains(java.lang.String st, java.util.regex.Pattern pattern)`
    `static int` | `countLeadingQualifiers(java.lang.String string, java.lang.String qualifier)`
    `static int` | `countMatches(java.lang.String string, java.lang.String regex)`
    `static int` | `countMatches(java.lang.String string, java.lang.String regex, int matchLen)`
    `static int` | `countTrailingQualifiers(java.lang.String string, java.lang.String qualifier)`
    `static java.lang.String` | `escape(java.lang.String str)` Escapes a given string for regex.
    `static java.lang.String` | `find(java.lang.String searchIn, java.util.regex.Pattern findWhatPattern, int group)`
    `static java.lang.String` | `find(java.lang.String searchIn, java.lang.String findWhatRegex, int group)`
    `static java.util.List<java.lang.String>` | `findAll(java.lang.String searchIn, java.util.regex.Pattern findWhatPattern, int group)`
    `static java.util.List<java.lang.String>` | `findAll(java.lang.String searchIn, java.lang.String findWhatRegex, int group)`
    `static int` | `getGroupAtPos(java.lang.String regex, int position)`
    `static java.util.regex.Pattern` | `getPattern(java.lang.String regex)`
    `static java.util.List<Range>` | `getQuotedAreas(java.lang.String regex)`
    `static boolean` | `matches(java.lang.String st, java.util.regex.Pattern pattern)`
    `static java.lang.String` | `replaceAll(java.lang.String string, java.util.regex.Pattern pattern, int group, java.lang.String replacement)`
    `static java.lang.String` | `replaceAll(java.lang.String string, java.lang.String regex, int group, java.lang.String replacement)`
    `static java.lang.String` | `updateGroupReferences(java.lang.String regex, int groupNum)` Adjust values in back references to capturing groups (like \1) of a given regex.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### RegexUtil

          public RegexUtil()

  - ### Method Detail

    - #### getPattern

          public static java.util.regex.Pattern getPattern(java.lang.String regex)

    - #### find

          public static java.lang.String find(java.lang.String searchIn,
                              java.lang.String findWhatRegex,
                              int group)

    - #### find

          public static java.lang.String find(java.lang.String searchIn,
                              java.util.regex.Pattern findWhatPattern,
                              int group)

    - #### findAll

          public static java.util.List<java.lang.String> findAll(java.lang.String searchIn,
                                                 java.lang.String findWhatRegex,
                                                 int group)

    - #### findAll

          public static java.util.List<java.lang.String> findAll(java.lang.String searchIn,
                                                 java.util.regex.Pattern findWhatPattern,
                                                 int group)

    - #### replaceAll

          public static java.lang.String replaceAll(java.lang.String string,
                                    java.util.regex.Pattern pattern,
                                    int group,
                                    java.lang.String replacement)

    - #### replaceAll

          public static java.lang.String replaceAll(java.lang.String string,
                                    java.lang.String regex,
                                    int group,
                                    java.lang.String replacement)

    - #### countMatches

          public static int countMatches(java.lang.String string,
                         java.lang.String regex)

    - #### countMatches

          public static int countMatches(java.lang.String string,
                         java.lang.String regex,
                         int matchLen)

    - #### countLeadingQualifiers

          public static int countLeadingQualifiers(java.lang.String string,
                                   java.lang.String qualifier)

    - #### countTrailingQualifiers

          public static int countTrailingQualifiers(java.lang.String string,
                                    java.lang.String qualifier)

    - #### escape

          public static java.lang.String escape(java.lang.String str)

      Escapes a given string for regex.
      Parameters:
        `str` - the given string
      Returns:
        escaped string

    - #### matches

          public static boolean matches(java.lang.String st,
                        java.util.regex.Pattern pattern)

    - #### contains

          public static boolean contains(java.lang.String st,
                         java.util.regex.Pattern pattern)

    - #### getQuotedAreas

          public static java.util.List<Range> getQuotedAreas(java.lang.String regex)

    - #### getGroupAtPos

          public static int getGroupAtPos(java.lang.String regex,
                          int position)

    - #### updateGroupReferences

          public static java.lang.String updateGroupReferences(java.lang.String regex,
                                               int groupNum)

      Adjust values in back references to capturing groups (like \1) of a given regex. This method needs to be called when a new group is added to a regex, and the regex contains back references to existing groups. Values in the references having number equal or greater than groupNum, should be increased by 1.
      Parameters:
        `regex` - the given regex containing back references to capturing groups.
        `groupNum` - the number of the new group.
      Returns:
        the given regex with updated references.