-1

I'm new to using Regex I want to get macapp value in url just get number 12 to String how do that ?

String url = "stackoverflow.com/questions/ask:macapp=12";

Pattern pattern = ;// ?

Matcher matcher =;// ?


if(matcher.find()) 
{
    //result = only 12
}

THX for your TIME
Nick
  • 123,192
  • 20
  • 49
  • 81
  • 1
    It's not quite clear what your question is. Do you want to extract a number that appears at the end of a string? Or a number that appears after the word `macapp=`? What does break have to do with it? – Eritrean Oct 21 '19 at 21:45

1 Answers1

1
Pattern p = Pattern.compile("^.*:macapp=(\\d+)$");
Matcher m = p.matcher(s);
if (m.find()) {
  int n = Integer.valueOf(m.group(1));
  ...
}
Jeffrey Blattman
  • 21,781
  • 9
  • 77
  • 132