用的python的re,有一段文本, 我想匹配第一个\n\n之前的所有东西,包括\n包括文字。试了很多方法不是全部删掉,就是只删了\n\n的上一行
4条回答 默认 最新
- huasa2239635117 2017-08-01 01:41关注
string pattern = txtBiaoDaShi.Text; pattern = "(\n\n)"; Regex reg = new Regex(pattern); string input = "hello1" + "\n" + "hello2" + "\n\n" + "word"; bool d = reg.IsMatch(input); if (reg.IsMatch(input)) { var t = reg.Matches(input); Match oneMatch = reg.Match(input); int index = oneMatch.Index; var tt = input.Substring(0, index); }
tt的结果是:hello1\nhello2
解决 无用评论 打赏 举报