Example Analysis of regular expression and carriage return newline character in C #
I would like to share with you the example analysis of regular expressions and carriage return newline characters in C#. I hope you will gain something after reading this article. Let's discuss it together.
In C #, when reading the contents of a text file, there are often many carriage return newline characters ("\ r\ n"), which are generally invisible but real. At this point, the use of regular expressions for matching, you need to consider its existence. There is such a problem today:
The contents of the text file are as follows:
DT 20180101000000WT-1.1SL 31.4WL 203DT 20180101000000AT-4.1BP 1023.7HU 26RN 99999.9WS 1.92.094 3.479 2111 4.683 2103
Using the regular expression: WT\ s + (?. +) $, the result is no match. The reason is that the read text contains a lot of carriage return newline characters "\ r\ n". For example, in the line of WT-1.1, the substance is
"WT-1.1\ r\ n", when the line trailing character "$" has no effect. It should be said that reading the contents of the file directly and using regular expression matching will not work.
Change the regular expression to:
WT\ s + (?. +)\ r\ nAfter reading this article, I believe you have some understanding of "sample analysis of regular expressions and carriage return newline characters in C#". If you want to know more about it, welcome to follow the industry information channel. Thank you for reading!