2 possible strings contained in a log file:
1) "some text then https://myhost.ab.us2.myDomain.com and then some more text"
OR:
2) "some text then myhost.ab.us2.myDomain.com and then some more text"
The "myDomain.com"
is constant, so we can look for that hard-coded in the regex.
In both cases, they are not at the start of the line, but in the middle.
Need to extract "myhost"
out of the line, if it matches.
I've tried positive look behind using "https://"
OR "\\s{1}"
. The https://
by itself works:
Matcher m = Pattern.compile("https://(.+?)\\.(.+?)\\.(.+?)\\.myDomain\\.com\\s").matcher(input);
I'm want to add an "or" in there so it matches with "https://"
or "<space>"
("https://|//s{1}"
), but it always grabs the entire string up to the start of the first space.
For now, I've settled on splitting the string into String[]
and checking if it contains "myDomain"
. I worked so long on this I wanted to learn what the best answer is.