Java: Unterschied zwischen den Versionen

Aus wiki
Wechseln zu: Navigation, Suche
(Pattern Matching)
(Pattern Matching)
Zeile 3: Zeile 3:
 
=== Pattern Matching ===
 
=== Pattern Matching ===
 
Named Matching
 
Named Matching
  private String getAccessToken(String responseURL) {
+
 
  String patternString = "http://localhost/client#(access_token%3D <http://localhost:8080/mobile-client#%28access_token%3D> (?<TOKEN>.+))%26token_type(.+%)";
+
  private @Nullable String getToken(@Nonnull String responseURL) {</pre>
 +
  String patternString = "http://www.example.com/example#(token%3D(?<TOKEN>.+))%26otherstuff(.+%)";
 
  Pattern pattern = Pattern.compile(patternString);
 
  Pattern pattern = Pattern.compile(patternString);
 
  Matcher matcher = pattern.matcher(responseURL);
 
  Matcher matcher = pattern.matcher(responseURL);
  matcher.find();
+
  if(matcher.find()){
 
  return matcher.group("TOKEN");
 
  return matcher.group("TOKEN");
 +
}
 +
return null;
 
  }
 
  }

Version vom 28. Juli 2014, 16:08 Uhr

Code Snippets

Regex

Pattern Matching

Named Matching

private @Nullable String getToken(@Nonnull String responseURL) {</pre>
String patternString = "http://www.example.com/example#(token%3D(?<TOKEN>.+))%26otherstuff(.+%)";
Pattern pattern = Pattern.compile(patternString);
Matcher matcher = pattern.matcher(responseURL);
if(matcher.find()){
return matcher.group("TOKEN");
}
return null;
}