Loading

The .NET Match and Regex Modes

The .NET Match and Regex Modes

RegexOptions option

(?mode)

Description

.Singleline

s

Causes dot to match any character (使"."可以匹配新行符的模式称“单行模式”).

.Multiline

m

Expands where ^ and $ can match (多行模式。更改^和$的含义,使他们分别在任意一行的行首和行

尾匹配,而不仅仅在整个字符串的开头和结尾匹配。)

.IgnorePatternWhitespace

x

Sets free-spacing and comment mode (消除模式中的非转义空白和并启用由#标记的注释).

.IgnoreCase

i

Turns on case-insensitive matching(忽略大小写)

.ExplicitCapture

n

Turns capturing off for (⋯), so only (?< name >⋯) capture(启用“显示”捕获).

.ECMAScript

 

Restricts \w, \s, and \d to match ASCII characters only, and more .

.RightToLeft

 

The transmission applies the regex normally, but in the opposite direction (starting at the end of the string and moving toward the start). Unfortunately, buggy

.Compiled

 

Spends extra time up front optimizing the regex so it matches more quickly when applied

 多行模式只影响行首行尾的锚定(anchor)“^”和“$,而单行模式只影响“.”。

在.NET Framework中使用正则表达式类时,

可以用类似下面的语句来激活单行模式:Regex.Match(“string”,”regex”,RegexOptions.SingleLine)

定义锚定匹配每一个新行符的前面和后面位置:Regex.Match("string", "regex", RegexOptions.Multiline)

应用:string str = Regex.Replace(Original, "^", "> ", RegexOptions.Multiline)--将会在每行的行首插入“> ”。

 

posted @ 2008-08-02 21:16  .net's  阅读(813)  评论(0)    收藏  举报