I'm trying to extract a piece of string from a larger string.
Example:
String value;
...etc...
value = someMethod();
// Here value equals a large string text
value;
I want to extract a subset of this string which begins with "path=" and everything after it.
Elaborated Example:
if value equals:
StartTopic topic=testParser, multiCopy=false, required=true, all=false, path=/Return/ReturnData/IRSW2
I want only "path=/Return/ReturnData/IRSW2" so on and so forth.
How could I do this in Java?
This is what I currently have:
if(value.contains("path")) {
String regexStr = FileUtils.readFileToString(new File("regex.txt"));
String escapedRegex = StringEscapeUtils.escapeJava(regexStr);
System.out.println(value.replaceAll(escapedRegex), "$1");
}
This doesn't work! Just outputs the whole string again
Contents of regex.txt:
/path=([^\,]+)/