Java ReplaceAll is often used, so here is a brief introduction to its usage, which can be used in regular,
Use ?! Can ignore case,
Brief example:
(? i) ABC indicates that ABC ignores case
A (? i) BC indicates that BC ignores case
A ((? i) b) C means that only B ignores case
You can also Pattern.compile (rexp,pattern.case_insensitive) that the whole ignores case
Like what:
public string Transform2htmltag (string refstring) {//pattern: [tagName style = Stylevalue]text content[/TagName]//rep Lace to: <tagname style=\ "stylevalue\" >text content</tagname>.://e.g Text[span; color:red;font-family: ' Arial ']123 Content[/span]//replace to:text<span style= "font-size:14px;color:red;
font-family: ' Arial ' ">123 content</span> String retvalue =" ";
if (null!= refstring &&!refstring.trim (). IsEmpty ()) {RetValue = Refstring.trim (); RetValue = Retvalue.replaceall ("\\[" ([a-za-z][a-za-z0-9]*) \\s*style\\s*=\\s* ([^\\[]*) \] "," <$1 style=\ "$2\" >
");
RetValue = Retvalue.replaceall ("\\[/\\s* ([a-za-z][a-za-z0-9]*) \\s*\\]", "</$1>"); About handle all XSS security reason, must put this to the end position RetValue = Retvalue.replaceall ("(? i) < (. *) HT
TPS ([^<]*) > "," <$1h-t-t-p-s$2> ");
RetValue = Retvalue.replaceall ("(? i) < (. *) HTTP ([^<]*) >", "<$1h-t-t-p$2>"); RetValue =Retvalue.replaceall ("(? i) < (. *) SSL2 ([^<]*) >", "<$1s-s-l-2$2>");
RetValue = Retvalue.replaceall ("(? i) < (. *) SSL ([^<]*) >", "<$1s-s-l$2>");
return retvalue;
}For example, here are examples of
RetValue = Retvalue.replaceall ("(? i) < (. *) HTTPS ([^<]*) >", "<$1h-t-t-p-s$2>"); In
HTTPSIs case-insensitive, that is to say, Https,https,https,https,https and other combinations of uppercase and lowercase are matched to facilitate matching operations,
Another example:
Replace:[size = sizevaluepx]text[/Size]
//to: <span style= "FONT-SIZE:SIZEVALUEPX;" >text</span>
//attend:px is the size unit pixel
//eg.: [size = 16px] text000 [/size] Convert to: <span St Yle= "16PX;" >text000</span>
RetValue = Retvalue.replaceall ("(? i) \\[\\s*size\\s*=\\s* ([^\\[]*) \]", "<span Style=\ "font-size:$1;\" (">");
RetValue = Retvalue.replaceall ("(? i) \\[/\\s*size\\s*\\]", "</span>");
Size can ignore case, or match different combinations such as size,size,size,size, which can be replaced by this regular match, and then converted to HTML format.
Brief introduction, remember to write, welcome to Pat Bricks ...