正则表达式的第一页

pap*_*zzo -8 .net c# regex

正则表达首页?
一切都到分页符\ f

这只找到第一页的最后一行"第一页的
结尾"

我需要所有4行
"第一页"
"第二行"
"搜索字符串"
" 第一页结尾"

添加\ s没有为我修复
[\ s | S]只是吹过\ f并找到所有内容

string input = "first page" + Environment.NewLine +
               "second line" + Environment.NewLine +
               "search string" + Environment.NewLine +
               "end of page one\f" +
               "second page" + Environment.NewLine +
               "second line" + Environment.NewLine +
               "search string" + Environment.NewLine +
               "end of page two\f";
public string Input { get { return input; }}
public string FirstPage
{
    get
    {
        //@"((.*)\f)\1(<SEARCH STRING GOES HERE>)"); this is what in the end I need to do
        string pattern = @"(.*)\f";
        Match  match = Regex.Match(input, pattern, RegexOptions.Multiline);
        if (match != null)
        {
            return match.Value;
        }
        else
            return "noot found";    
    }
}
Run Code Online (Sandbox Code Playgroud)

Guf*_*ffa 6

.除非你使用不匹配换行符Singleline选项.使用\W\w匹配任何字符的集合或将选项更改为Singleline.

?*乘数之后使用使其变得非贪婪,否则它将匹配所有内容然后追溯到最后一个\f.

string pattern = @"([\W\w]*?)\f";
Match  match = Regex.Match(input, pattern, RegexOptions.Multiline);
Run Code Online (Sandbox Code Playgroud)

要么:

string pattern = @"(.*?)\f";
Match  match = Regex.Match(input, pattern, RegexOptions.Singleline);
Run Code Online (Sandbox Code Playgroud)