Using system;
Using system. Text. regularexpressions;
Using system. collections;
Namespace ccnuhome. toolsobject
{
/// <Summary>
/// Regular summary.
/// </Summary>
Public class regular
{
Public regular ()
{
//
// Todo: add the constructor logic here
//
}
Public String getfirstnchar (string instr, int firstn)
{
String outstr = "";
Instr = instr. Replace (@"""","");
Regex r = new Regex (@"((? <=>) [/W ,. : ",." "% ?! ()@?! ()] * (? = <) | ((? <=/B) [/w ,. : ",." "% ?! ()@?! ()] * (? = <) | ((? <=>) [/W ,. : ",." "% ?! ()@?! ()] * (? =/B ))");
MatchCollection mc = r. Matches (instr );
For (int I = 0; I <mc. Count; I ++)
{
Outstr + = mc [I]. Value;
}
If (outstr. Length <firstN)
Return outstr;
Return outstr. Substring (0, firstN );
}
Public ArrayList GetHref (string inputString)
{
ArrayList al = new ArrayList ();
Regex r;
Match m;
R = new Regex ("href // s * = // s *(? :/"(? <1> [^/"] *)/" | (? <1> // S + ))",
RegexOptions. IgnoreCase | RegexOptions. Compiled );
For (m = r. Match (inputString); m. Success; m = m. NextMatch ())
{
Al. Add (m. Groups [1]. Value );
}
Return al;
}
Public arraylist getimages (string inputstring)
{
Arraylist Al = new arraylist ();
RegEx R;
Match m;
R = new RegEx ("img/S * src = // s *(? :/"(? <1> [^/"] *)/" | (? <1> // s + ))",
Regexoptions. ignorecase | regexoptions. Compiled );
For (M = R. Match (inputstring); M. success; M = M. nextmatch ())
{
Al. Add (M. Groups [1]. value );
}
Return al;
}
Public String getnimage (string inputstring, int index)
{
Arraylist Al = getimages (inputstring );
Return (string) al [Index];
}
}
}