我在C#中找到了这个正则表达式提取器代码.有人可以告诉我这是如何工作的,我如何用Java编写等价的东西?
// extract songtitle from metadata header.
// Trim was needed, because some stations don't trim the songtitle
fileName =
Regex.Match(metadataHeader,
"(StreamTitle=')(.*)(';StreamUrl)").Groups[2].Value.Trim();
Run Code Online (Sandbox Code Playgroud)
这应该是你想要的.
// Create the Regex pattern
Pattern p = Pattern.compile("(StreamTitle=')(.*)(';StreamUrl)");
// Create a matcher that matches the pattern against your input
Matcher m = p.matcher(metadataHeader);
// if we found a match
if (m.find()) {
// the filename is the second group. (The `(.*)` part)
filename = m.group(2);
}
Run Code Online (Sandbox Code Playgroud)