As we all know, under. NET, a dedicated Regex class is used to process regular expressions. I have been programming for several years and have been more or less familiar with the regular expression to process strings. It can be said that I have little experience in writing regular expressions.
These years have been. NET programming, there are a lot of contacts with the Regex class, and many of the RegexOptions options have long been found that many of them are not in the regular expressions of other languages (such as C/C ++, JS, such as Compiled, ExplicitCapture, RightToLeft, and Singleline. Singleline and Multiline are literally "single-row mode" and "multi-row mode". I won't explain much about the specific meaning, anyone who uses a regular expression knows this. In my subconscious, I always think that these two items are mutually exclusive and cannot exist at the same time. I have been subconsciously avoiding them and using them at the same time.
Recently, when I was working on a regular expression tool, I had been working with this idea. I made these two items into RadioButton single handler. After the program was written, I also debugged them, it should be said that there is no problem in most cases-many times we come into contact with only one line of strings to be matched, at least I am like this, besides, I am not a professional tester. ------ A colleague told me one day that some problems may occur in understanding these two items during a usage process, I went back and checked the relevant documents carefully ------ I was really wrong. Literally, this means mutex, no problem, but the two modifiers are different. The Multiline modifier is ^ and $, that is, when there is no Multiline, match ^ and $ with the beginning and end of each line (ending with \ n). When Multiline exists, it matches the beginning and end of the entire string; singleline modifies '. ', that is, all characters (including \ n) are matched when there is a Singleline. If there is no Singleline, all characters except \ n are matched. The two are essentially irrelevant, and they are not mutually exclusive.
Let's look at the RegexOptions enumeration. This is an enumeration with the Flag feature. It indicates that the items in it can be combined at will, which indirectly demonstrates that Multiline and Singleline can coexist. Alas, I only blame myself for being too advanced to understand the meaning of each item. I just take it for granted.
I knew that I was wrong and immediately changed the program. Fortunately, it was easier for the program to be changed. After the program was changed, I also looked at the regular expression in JS, is there such a problem (my program is used to generate. NET and JS regular expressions), but it's amazing that JS should be much simpler, except for gim, so g and I won't talk about it, not in the scope of this article. M and Multiline. To achieve the Singleline effect in. NET in JS, you can only use [. \ n.