Java: Unterschied zwischen den Versionen
Aus wiki
(→Pattern Matching) |
(→Pattern Matching) |
||
| Zeile 3: | Zeile 3: | ||
=== Pattern Matching === | === Pattern Matching === | ||
Named Matching | Named Matching | ||
| − | private String | + | |
| − | String patternString = "http:// | + | 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;
}