![](/img/trans.png)
[英]How do you write a regular expression that matches all but the first occurrence?
[英]How to write regular expression to match first occurrence of ending word
我需要刪除文本下方以結轉余額開頭的行
結轉余額170,806.80 3,558.48 167,248.32 \\ r \\ n <some other text>
\\ r \\ n
結果文本應為
<some other text>
\\ r \\ n
我在下面的正則表達式中嘗試過Regex.Replace(body, _regex, "",RegexOptions.Singleline)
,但它與字符串末尾的\\ r \\ n匹配,並且主體為空白。
Balance carried forward.*[\r\n|\r|\n]
嘗試以下模式:
^Balance carried forward[^\r\n]*(?:\r\n|\r|\n)
說明:
^ // match at the start of a line
Balance carried forward
[^\r\n]* // match anything that's not a newline
(?:\r\n|\r|\n) // finally, match a newline
我會做:
^Balance carried forward.*?\R
其中\\R
代表\\n
, \\r
或\\r\\n
。
如果無法識別\\R
,請使用:
^Balance carried forward.*?[\r\n]+
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.