попробовать это:
(?<=")\w+\.\w+(?=")
Это не будет включать цитаты в матче.
ПРИМЕЧАНИЕ. Я сделал одно предположение с этим регулярным выражением. Я предполагаю, что имя файла будет содержать только один символ .
. Таким образом, my.file.txt
не будет соответствовать. Если вам это нужно, дайте мне знать, и я обновлю его.
Ниже показано, как использовать это в коде C# для повторения всех совпадений.
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
}
и вот некоторые комментарии, которые помогут вам понять:
@"
(?<= # 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
)
"
Почему использовать 'Regex' для этого? Похоже, 'string.Split' будет работать красиво. – Oded
@Oded Мне хотелось бы увидеть код :) –
@the_joric - Что? 'myString.Split ('' ') [1]'? – Oded