|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.jutil.java.regex.RegexReplacer
A class of object the replace regular expressions for others.
For example, it can replace a regular expression in a file and write the output to another file.
At this moment, we use JRegex instead of jdk 1.4 regular expressions because:
This means that this class will change in the future, and the
Pattern
class will probably disappear since it's
only adapts the JRegex Pattern class to the interface of java.util.regex.Pattern
in order to simplify porting afterwards.
Constructor Summary | |
RegexReplacer(java.lang.String pattern,
java.lang.String replacement)
public behavior pre pattern != null; pre replacement != null; pre (* pattern must be a valid regular expression *); post getPattern().pattern().equals(pattern); // The pattern is a multi line pattern. post getPattern().flags() == Pattern.MULTILINE; post getReplacement() == replacement; Initialize a new RegexReplacer for the given pattern and replacement. |
|
RegexReplacer(java.lang.String pattern,
java.lang.String replacement,
int flags)
public behavior pre pattern != null; pre replacement != null; pre (* pattern must be a valid regular expression *); pre (* flags must be a valid flag for a pattern. |
Method Summary | |
jregex.Pattern |
getPattern()
public behavior post \result != null; Return the pattern of this RegexReplacer. |
java.lang.String |
getReplacement()
public behavior post \result != null; Return the replacement string of this RegexReplacer. |
static void |
main(java.lang.String[] args)
|
void |
replace(java.io.File input,
java.io.File output)
public behavior pre input != null; pre output != null; post (* all occurrences of getPattern() will be replaced by getReplacement() in the input file, and the result will be written the output file. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public RegexReplacer(java.lang.String pattern, java.lang.String replacement)
pattern
- a String containing the pattern to be replaced.replacement
- a String containing the pattern to replace the matched pattern.public RegexReplacer(java.lang.String pattern, java.lang.String replacement, int flags)
pattern
- A String containing the pattern to be replaced.replacement
- A String containing the pattern to replace the matched pattern.flags
- The flags for the pattern.Method Detail |
public void replace(java.io.File input, java.io.File output) throws java.io.FileNotFoundException, java.io.IOException
Replace all occurrences of the pattern of this RegexReplacer in the input file by the replacement of this RegexReplacer, and write the result to the output file.
Both File objects may refer to the same real file.
input
- The file in which the pattern must be replaced.output
- The file to which the result must be written.public jregex.Pattern getPattern()
public java.lang.String getReplacement()
public static void main(java.lang.String[] args) throws java.lang.Exception
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |