Class RegexReplace
- java.lang.Object
-
- ch.supertomcat.supertomcatutils.regex.RegexReplace
-
public class RegexReplace extends Object
Search and Replace by Regular Expressions
-
-
Constructor Summary
Constructors Constructor Description RegexReplace()ConstructorRegexReplace(String search, String replace)ConstructorRegexReplace(String search, String replace, boolean compilePattern)Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description StringdoReplace(String input)Replace-Method which returns the replaced input String or the input if the pattern is not compiled, the input is empty or the replacement failedStringdoReplaceMatchRegion(String input, int start)Replace-Method which only returns the match region or an empty Stirng if the pattern is not compiled, start parameter is invalid (negative or higher than input length) or the input is emptyintdoSearch(String input, int start)Search-Method Returns the start-position when found the pattern Returns -1 if not found the pattern or an error occuredprotected booleanexecutionNeeded(String input)Checks if execution of search or replace is possible and neededprotected booleanexecutionNeeded(String input, int start)Checks if execution of search or replace is possible and neededStringgetReplace()Returns the Replace-StringStringgetSearch()Returns the Search-StringvoidsetReplace(String replace)Sets the Replace-StringvoidsetSearch(String search)Sets the Search-String and try to compile the PatternvoidsetSearch(String search, boolean compilePattern)Sets the Search-String and try to compile the Pattern.
-
-
-
Constructor Detail
-
RegexReplace
public RegexReplace()
Constructor
-
RegexReplace
public RegexReplace(String search, String replace) throws PatternSyntaxException
Constructor- Parameters:
search- Regex Search Patternreplace- Replacement String- Throws:
PatternSyntaxException
-
RegexReplace
public RegexReplace(String search, String replace, boolean compilePattern) throws PatternSyntaxException
Constructor- Parameters:
search- Regex Search Patternreplace- Replacement StringcompilePattern- True if pattern should be compiled, false otherwise- Throws:
PatternSyntaxException
-
-
Method Detail
-
getSearch
public String getSearch()
Returns the Search-String- Returns:
- Search-String
-
setSearch
public void setSearch(String search) throws PatternSyntaxException
Sets the Search-String and try to compile the Pattern- Parameters:
search- Search-String- Throws:
PatternSyntaxException
-
setSearch
public void setSearch(String search, boolean compilePattern) throws PatternSyntaxException
Sets the Search-String and try to compile the Pattern. Note: If compilePattern is false, then the pattern Member is set to null.- Parameters:
search- Search-StringcompilePattern- True if pattern should be compiled, false otherwise- Throws:
PatternSyntaxException
-
getReplace
public String getReplace()
Returns the Replace-String- Returns:
- Replace-String
-
setReplace
public void setReplace(String replace)
Sets the Replace-String- Parameters:
replace- Replace-String
-
executionNeeded
protected boolean executionNeeded(String input)
Checks if execution of search or replace is possible and needed- Parameters:
input- Input- Returns:
- True if execution of search or replace is possible and needed, false otherwise
-
executionNeeded
protected boolean executionNeeded(String input, int start)
Checks if execution of search or replace is possible and needed- Parameters:
input- Inputstart- Start Index- Returns:
- True if execution of search or replace is possible and needed, false otherwise
-
doSearch
public int doSearch(String input, int start)
Search-Method Returns the start-position when found the pattern Returns -1 if not found the pattern or an error occured- Parameters:
input- Inputstart- Startposition- Returns:
- Found position
-
doReplace
public String doReplace(String input)
Replace-Method which returns the replaced input String or the input if the pattern is not compiled, the input is empty or the replacement failed- Parameters:
input- Input- Returns:
- Replaced String
-
doReplaceMatchRegion
public String doReplaceMatchRegion(String input, int start)
Replace-Method which only returns the match region or an empty Stirng if the pattern is not compiled, start parameter is invalid (negative or higher than input length) or the input is empty- Parameters:
input- Inputstart- Startposition- Returns:
- Replaced String
-
-