Java: Unterschied zwischen den Versionen

Aus wiki
Wechseln zu: Navigation, Suche
(Pattern Matching)
Zeile 3: Zeile 3:
 
=== Pattern Matching ===
 
=== Pattern Matching ===
 
Named Matching
 
Named Matching
 
+
<syntaxhighlight lang="java">
 
  private @Nullable String getToken(@Nonnull String responseURL) {</pre>
 
  private @Nullable String getToken(@Nonnull String responseURL) {</pre>
 
  String patternString = "http://www.example.com/example#(token%3D(?<TOKEN>.+))%26otherstuff(.+%)";
 
  String patternString = "http://www.example.com/example#(token%3D(?<TOKEN>.+))%26otherstuff(.+%)";
Zeile 13: Zeile 13:
 
  return null;
 
  return null;
 
  }
 
  }
 +
</syntaxhighlight>

Version vom 28. Juli 2014, 16:38 Uhr

Code Snippets

Regex

Pattern Matching

Named Matching <syntaxhighlight lang="java">

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;
}

</syntaxhighlight>