How should I parse the following String
using Java to extract the file path?
?
stands for any number of random charaters
_
stands for any number of white spaces (no new line)
?[LoadFile]_file_=_"foo/bar/baz.xml"?
Example:
10:52:21.212 [LoadFile] file = "foo/bar/baz.xml"
should extract foo/bar/baz.xml
String regex = ".*\\[LoadFile\\]\\s+file\\s+=\\s+\"([^\"].+)\".*";
Matcher m = Pattern.compile(regex).matcher(inputString);
if (!m.find())
System.out.println("No match found.");
else
String result = m.group(1);
The String
in result should be your file path. (assuming I didn't make any mistakes)
You should take a look at the Pattern
class for some regular expression help. They can be a very powerful string manipulation tool.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With