Friday, July 23, 2010

07/23 : Regex Test

 

Long time no blog.

Regex : ([a-zA-Z])+(?=\.)

// (?=) means no capture

C# Code

public static Regex regex = new Regex(
     "([a-zA-Z])+(?=\\.)",
   RegexOptions.IgnoreCase
   | RegexOptions.CultureInvariant
   | RegexOptions.IgnorePatternWhitespace
   | RegexOptions.Compiled
   );

MatchCollection ms = regex.Matches("www.yahoo.domian.com");

//result:

ms[0]=”www”

ms[1]=”yahoo”

ms[2]=”domain”

  • 正则表达式“([a-z])\1{2}”也就表达连续三个相同的小写字母。

反向引用: \number

  • <([a-zA-A]\d?)>[^<]*</\1>

input : <p>fasdfa</p><h2>asdfa</h2>

result:

(1)<p>fasdfa</p>

(2)<h2>asdfa</h2>

0 Comments:

Post a Comment

<< Home