Regular expression class commonly used in an article system

xiaoxiao2021-03-06  40

Using system.text.regularexpressions; using system.collections;

Namespace ccnuhome.toolsObject {///

/// regular's summary description. /// public class regular {public regular () {// // TODO: Add constructor logic //}

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

Public arraylist gethref (string infutstring) {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 infutstring, int index) {arraylist al = GetImages (InputString); return (string) al [index];}}}

转载请注明原文地址:https://www.9cbs.com/read-66009.html

New Post(0)