We declare an array
Public Static New regex[];
The next key regular expression:
RegexOptions options =Regexoptions.none; //Nested template tags (compatible)r[0] =NewRegex (@"<!--{Template (skin=\\ "" ([^\[\]\{\}\s]+) \ \ "" (?: \ s+))?) src= (?: \ /|\\ "") ([^\[\]\{\}\s]+) (?: \ /|\\"")(?:\ s*)}-->", Options); //template path Label (new)r[1] =NewRegex (@"<!--{Templateskin (= (?: \ \ "") ([^\[\]\{\}\s]+) (?: \ \""))?) (?:\ s*)}-->", Options); //namespace Tagsr[2] =NewRegex (@"<!--{namespace (?: ""?) ([\s\s]+?) (?:""?)} -", Options); //C # code tagsr[3] =NewRegex (@"<!--{csharp}--> ([\s\s]+?) <!--{/csharp}-->", Options); //Loop Loop (discard)r[4] =NewRegex (@"<!--{Loop (([^\[\]\{\}\s]+) \)?) ([^\[\]\{\}\s]+) ([^\[\]\{\}\s]+)} -", Options); //foreach Loop (new)r[5] =NewRegex (@"<!--{foreach (?: \ s*) \ (([^\[\]\{\}\s]+) ([^\[\]\{\}\s]+) in ([^\[\]\{\}\s]+) \) (?: \ s*)}-->", Options); //For Loop (new)r[6] =NewRegex (@"<!--{for\ ([^\ (\) \[\]\{\}]+) \) (?: \ s*)}-->", Options); //If statement label (discard)r[7] =NewRegex (@"<!--{if (?: \ s*) ([^\s]+) ((?: \ s*) (\|\| | \&\&) (?: \ s*) ([^\s]+))?) (?:\ s*)}-->", Options); r[8] =NewRegex (@"<!--{Else ((?: \ s*) if (?: \ s*) ([^\s]+) ((?: \ s*) (\|\| | \&\&) (?: \ s*) ([^\s]+))) (?:\ s*)}-->", Options); //if Statement label (new)r[9] =NewRegex (@"<!--{if\ (([^\s]+) ((?: \ s*) (\|\| | \&\&) (?: \ s*) ([^\s]+))?) \)(?:\ s*)}-->", Options); r[Ten] =NewRegex (@"<!--{Else ((?: \ s*) if\ (([^\s]+) ((?: \ s*) (\|\| | \&\&) (?: \ s*) ([^\s]+))?) \))(?:\ s*)}-->", Options); //Loop and end of Judgment label (compatible)r[ One] =NewRegex (@"<!--{\/(?: Loop|foreach|for|if) (?: \ s*)}-->", Options); //Continue labelr[ A] =NewRegex (@"<!--{continue (?: \ s*)}-->"); //Break labelr[ -] =NewRegex (@"<!--{break (?: \ s*)}-->"); //Request Labelr[ -] =NewRegex (@"(\{request\[([^\[\]\{\}\s]+) \]\})", Options); //Intercept String Tagsr[ the] =NewRegex (@"(<!--{cutstring\ ([^\s]+?), (. \d*?) \)}-->)", Options); //URL link Labelr[ -] =NewRegex (@"(<!--{linkurl\ ([^\s]*?) \)}-->)", Options); //declaring assignment Labels (compatible)r[ -] =NewRegex (@"<!--{set (\ (? ( [\w\.<>]+] (?: \) | ))?) (?:\ s*) \{? ( [^\s\{\}]+] \}? (?:\ s*) = (?: \ s*) (. *?) (?:\ s*)}-->", Options); //Data Variable Labelsr[ -] =NewRegex (@"(\{([^\[\]\{\}\s]+) \[([^\[\]\{\}\s]+) \]\})", Options); //Common Variable Tagsr[ +] =NewRegex (@"({([^\[\]/\{\}=: ' \s]+)})", Options); //time format conversion labelr[ -] =NewRegex (@"(<!--{datetostr\ ([^\s]+?), (. *?) \)}-->)", Options); //Integer Conversion labelr[ +] =NewRegex (@"(\{strtoint\ ([^\s]+?) \)\})", Options); //Direct Output Labelr[ A] =NewRegex (@"<!--{(?: Write |=) (?: \ s*) (. *?) (?:\ s*)}-->", options);
Look at a bunch of them! It's hard to feel like it's not going to be the main.
Now we're going to use the following method in the main talk about the Replace the statement if label
Stringstrtemplate= ""//Place the template content you want to replaceforeach(Match minchr[7]. Matches (strtemplate)) {Iscodeline=true; Strtemplate= Strtemplate.replace (m.groups[0]. ToString (),"\r\n\tif ("+ m.groups[1]. ToString (). Replace ("\\\"","\"") +") \r\n\t{"); } foreach(Match minchr[8]. Matches (strtemplate)) {Iscodeline=true; if(m.groups[1]. ToString () = =string. Empty) {strtemplate= Strtemplate.replace (m.groups[0]. ToString (),"\r\n\t}\r\n\telse\r\n\t{"); } Else{strtemplate= Strtemplate.replace (m.groups[0]. ToString (),"\r\n\t}\r\n\telse if ("+ m.groups[3]. ToString (). Replace ("\\\"","\"") +") \r\n\t{"); } } foreach(Match minchr[9]. Matches (strtemplate)) {Iscodeline=true; Strtemplate= Strtemplate.replace (m.groups[0]. ToString (),"\r\n\tif ("+ m.groups[1]. ToString (). Replace ("\\\"","\"") +") \r\n\t{"); } foreach(Match minchr[Ten]. Matches (strtemplate)) {Iscodeline=true; if(m.groups[1]. ToString () = =string. Empty) {strtemplate= Strtemplate.replace (m.groups[0]. ToString (),"\r\n\t}\r\n\telse\r\n\t{"); } Else{strtemplate= Strtemplate.replace (m.groups[0]. ToString (),"\r\n\t}\r\n\telse if ("+ m.groups[3]. ToString (). Replace ("\\\"","\"") +") \r\n\t{"); } }
Writing a template engine yourself is a hassle, and it may be easier to make direct dynamic pages and pseudo-static. It used to be a velocity template engine, and it was good to use.