正则表达首页?
一切都到分页符\ 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)
该.除非你使用不匹配换行符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)
| 归档时间: |
|
| 查看次数: |
90 次 |
| 最近记录: |