Java: Unterschied zwischen den Versionen
Aus wiki
| Zeile 3: | Zeile 3: | ||
=== Pattern Matching === | === Pattern Matching === | ||
Named Matching | Named Matching | ||
| − | <syntaxhighlight lang="java"> | + | <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> | + | </syntaxhighlight> |
Version vom 28. Juli 2014, 16:39 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>