Package net.sf.okapi.common
Class RegexUtil
- java.lang.Object
-
- net.sf.okapi.common.RegexUtil
-
public class RegexUtil extends Object
Collection of helper function for working with regular expressions.
-
-
Constructor Summary
Constructors Constructor Description RegexUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleancontains(String st, Pattern pattern)static intcountLeadingQualifiers(String string, String qualifier)static intcountMatches(String string, String regex)static intcountMatches(String string, String regex, int matchLen)static intcountTrailingQualifiers(String string, String qualifier)static Stringescape(String str)Escapes a given string for regex.static Stringfind(String searchIn, String findWhatRegex, int group)static Stringfind(String searchIn, Pattern findWhatPattern, int group)static List<String>findAll(String searchIn, String findWhatRegex, int group)static List<String>findAll(String searchIn, Pattern findWhatPattern, int group)static intgetGroupAtPos(String regex, int position)static PatterngetPattern(String regex)static List<Range>getQuotedAreas(String regex)static booleanmatches(String st, Pattern pattern)static StringreplaceAll(String string, String regex, int group, String replacement)static StringreplaceAll(String string, Pattern pattern, int group, String replacement)static StringupdateGroupReferences(String regex, int groupNum)Adjust values in back references to capturing groups (like \1) of a given regex.
-
-
-
Method Detail
-
replaceAll
public static String replaceAll(String string, Pattern pattern, int group, String replacement)
-
replaceAll
public static String replaceAll(String string, String regex, int group, String replacement)
-
escape
public static String escape(String str)
Escapes a given string for regex.- Parameters:
str- the given string- Returns:
- escaped string
-
getGroupAtPos
public static int getGroupAtPos(String regex, int position)
-
updateGroupReferences
public static String updateGroupReferences(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.
-
-