A common regular expression class in the Document System

Source: Internet
Author: User

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];
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.