-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
  • 138,499
  • 22
  • 57
  • 95
  • 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
  • 22,176
  • 9
  • 79
  • 134