versuchen Sie dies:
(?<=")\w+\.\w+(?=")
Dies wird nicht die Zitate im Spiel enthalten.
HINWEIS: Ich habe eine Annahme mit diesem Regex gemacht. Ich nehme an, dass der Dateiname nur ein einzelnes .
Zeichen enthält. So wird my.file.txt
nicht übereinstimmen. Wenn Sie das benötigen, lassen Sie es mich wissen und ich werde es aktualisieren.
Im Folgenden wird gezeigt, wie Sie dies im C# -Code verwenden, um alle Übereinstimmungen zu durchlaufen.
try {
Regex regexObj = new Regex(@"(?<="")\w+\.\w+(?="")");
Match matchResults = regexObj.Match(subjectString);
while (matchResults.Success) {
// matched text: matchResults.Value
// match start: matchResults.Index
// match length: matchResults.Length
matchResults = matchResults.NextMatch();
}
} catch (ArgumentException ex) {
// Syntax error in the regular expression
}
und hier sind einige Kommentare, die Sie es verstehen helfen:
@"
(?<= # Assert that the regex below can be matched, with the match ending at this position (positive lookbehind)
"" # Match the character “""” literally
)
\w # Match a single character that is a “word character” (letters, digits, and underscores)
+ # Between one and unlimited times, as many times as possible, giving back as needed (greedy)
\. # Match the character “.” literally
\w # Match a single character that is a “word character” (letters, digits, and underscores)
+ # Between one and unlimited times, as many times as possible, giving back as needed (greedy)
(?= # Assert that the regex below can be matched, starting at this position (positive lookahead)
"" # Match the character “""” literally
)
"
Warum 'Regex' dafür? Sieht aus wie 'string.split' wird gut funktionieren. – Oded
@Oded Ich möchte den Code sehen :) –
@the_joric - Was? 'myString.Split ('' ') [1]'? – Oded