In C, reading the contents of text files, there are often many return line breaks (“\r\\\ n”), although generally invisible, but they really exist. At this time, the use of regular expressions for matching, need to consider its existence. Today we are confronted with such a problem:
Text documents are as follows:
DT 20180101000000 WT -1.1 SL 31.4 WL 203 DT 20180101000000 AT -4.1 BP 1023.7 HU 26 RN 99999.9 WS 1.9 92 2.0 94 3.4 79 2111 4.6 83 2103
Use regular expressions:
WT\s+(?<WT>.+)$The result is that the matching value is not available. The reason is that the text you read contains many return line breaks ” r n”. For example, WT-1.1 line, the substance is
WT -1.1\r\n Then the line terminator “$” doesn’t work. It should be said that reading the contents of the file directly, using regular expression matching, will not work.
Change the regular expression to:
Above is the problem of regular expressions and return line breaks in C# introduced by Xiaobian. I hope it will be helpful to you. If you have any questions, please leave me a message and Xiaobian will reply to you in time. Thank you very much for your support to developpaer.