Home > Web Front-end > JS Tutorial > Detailed explanation of the use of regular expressions and carriage return and line feed characters

Detailed explanation of the use of regular expressions and carriage return and line feed characters

php中世界最好的语言
Release: 2018-05-25 10:01:07
Original
4589 people have browsed it

This time I will bring you a detailed explanation of the use of regular expressions and carriage return and line feed characters. What are the precautions for using regular expressions and carriage return and line feed characters? The following is a practical case, let's take a look.

In C#, when reading the content of a text file, there are often many carriage returns and line feeds ("\r\n"). Although they are generally invisible, they actually exist. At this time, when using regular expressions for matching, you need to consider its existence. I encountered such a problem today:

There is a text file with the following content:

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
Copy after login
Use

regular expression: WT\s (? . )$, the result is that no matching value can be obtained. The reason is that the text content read contains many carriage returns and line feeds "\r\n". For example, in the line WT -1.1, the actual content is

"

WT -1.1\r\n ". In this case, the line ending character "$" will not work. It should be said that if you directly read the file content and use regular expression matching, it will not work.

Change the regular expression to:

WT\s+(?<WT>.+)\r\n
Copy after login
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the PHP Chinese website!

Recommended reading:

Under what circumstances are padding and margin of inline elements invalid

Detailed explanation of steps to use JS array method

The above is the detailed content of Detailed explanation of the use of regular expressions and carriage return and line feed characters. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template