I am trying to figure out how to extract a substring from a string but the string contains a bracket, and Java then complains that it is not enclosed and if I try and escape it then complains that its not a valid escaped character.
I have the following string:
[Monitor Status](/monitors#2972550?)] · [[Edit Monitor](/monitors#2972550/edit)] · [[Related Logs](/logs?query=)]
%%%
I'm am trying to extract the number after /monitors#. The number is in two places and will always be the same in both places so I'm just trying to extract the first number.
Below is what I currently have:
Pattern pattern = Pattern.compile("[Monitor Status]/monitors#(\\d+)");
Matcher matcher = pattern.matcher(monitorDetails);
if (matcher.find())
{
String monitor_id = matcher.group(1);
monitorDetailsContainer.setVisibility(View.VISIBLE);
}
With the above, I don't have the (
between ] and /monitors but when I do Android Studio then says unclosed group
. If I try and escape the slash \(
it then says illegal escape character.
What I am expecting to get back is 2972550
.