Código:
Public Class programacion
Dim elemento As Color = Color.Firebrick
Dim atributo As Color = Color.Green
'funcion que colorea
Public Function Buscarcoma(ByVal pattern As String, ByVal RichTextBox As RichTextBox, ByVal cColor As Color)
Dim Resultados As MatchCollection
Dim Palabra As Match
Try
Dim obj_Expresion As New Regex(pattern.ToString, RegexOptions.IgnoreCase)
Resultados = obj_Expresion.Matches(RichTextBox.Text)
For Each Palabra In Resultados
With RichTextBox
.SelectionStart = Palabra.Index
.SelectionLength = Palabra.Length
.SelectionColor = cColor
Debug.Print(Palabra.Value)
End With
Next Palabra
Catch ex As Exception
MsgBox(ex.Message.ToString)
End Try
RichTextBox.DeselectAll()
Return 0
End Function
'html
Public Sub html(ByVal rtb As RichTextBox, ByVal rtb2 As RichTextBox)
Dim palabra(0 To 3) As Regex
'css desde # hasta {
palabra(3) = New Regex("[#]\s*([^ {]*)")
'elemento desde < hasta antes de >
palabra(0) = New Regex("[<]\s*([^> ]*)")
'elemento desde < hasta >
palabra(1) = New Regex("[<]\s*([^> ]*)")
Dim elem As String = palabra(1).ToString & ">"
'valor atributo desde " asta "
palabra(2) = New Regex("[" & Chr(34) & "]\s*([^" & Chr(34) & "]*)")
Dim atr As String = palabra(2).ToString() & Chr(34)
'nombre atributo antes de =
Dim palabra_0 As Char = "{", palabra_1 = "}", palabra_2 = ">", palabra_3 = "/>"
'colorear
'css
Buscarcoma(palabra_0.ToString, rtb, elemento)
Buscarcoma(palabra_1.ToString, rtb, elemento)
Buscarcoma(palabra_0.ToString, rtb2, elemento)
Buscarcoma(palabra_1.ToString, rtb2, elemento)
' valores de atributos ""
Buscarcoma(atr, rtb, atributo)
Buscarcoma(atr, rtb2, atributo)
' elemento desde < hasta antes de >
Buscarcoma(palabra(0).ToString, rtb2, elemento)
Buscarcoma(palabra(0).ToString, rtb, elemento)
'elemento css
Buscarcoma(palabra(3).ToString, rtb, Color.Green)
Buscarcoma(palabra(3).ToString, rtb2, Color.Green)
'elemento desde < hasta >
Buscarcoma(elem, rtb, elemento)
Buscarcoma(elem, rtb2, elemento)
'repaso
Buscarcoma(palabra_3.ToString, rtb, elemento)
Buscarcoma(palabra_2.ToString, rtb, elemento)
End Sub
'vb .net
Public Sub lenguajevb(ByVal rtb As RichTextBox, ByVal rtb2 As RichTextBox)
If rtb.TextLength <= 1 Then
Exit Sub
End If
Dim palabrasvb() As String = New String() {"AddHandler", "AddressOf", "Alias", "And", "Also()", " As ", "Boolean", "ByRef", " Byte", "ByVal", " Call", "Case", "Catch", "CBool", "CByte", "CChar", "CDate", "CDec" _
, "CDbl", "Char", "CInt", "Class", "CLng", "CObj", "Const", "Continue", "CSByte", "CShort", "CSng", "CStr", "CType", "CUInt", "CULng", "CUShort", "Date", "Decimal", "Declare", "Default", "Delegate", "Dim", "DirectCast", _
"Do", "Double", "Each", "Else", " End", "Enum", "Erase", "Error", "Event", "Exit", "False", "Finally", "For", "Friend", "Function", "Get", "GetType", "GetXMLNamespace", "Global", "GoSub", "GoTo", "Handles", " If ", "Implements", "Imports" _
, " In ", "Inherits", "Integer", "Interface", " Is ", "IsNot", "Let", "Lib", "Like", "Long", "Loop", " Me", "Mod", "Module", "MustInherit", "MustOverride", "MyBase", "MyClass", "Namespace", "Narrowing", "New", "Next", " Not ", "Nothing", "NotInheritable", "NotOverridable", "Object", " Of ", " On" _
, "Operator", "Option", "Optional", " Or ", "OrElse", "Overloads", "Overridable", "Overrides", "ParamArray", "Partial", "Public", "Property", "Protected", "Public", "RaiseEvent", "ReadOnly", "ReDim", "REM", "RemoveHandler", "Resume", "Region", "Return", "SByte", "Select", "Set", "Shadows", "Shared", "Short", "Single", "Static", "Step" _
, "Stop", "String", "Structure", "Sub", "SyncLock", "Then", "Throw", " To ", "True", " Try ", "TryCast", "TypeOf", "Variant", "Wend", "UInteger", "ULong", "UShort", "Using", "When", "While", "Widening", "With", "WithEvents", "WriteOnly", "Xor", "Aggregate", "Ansi()", "Assembly", "Auto", "Binary()", "Compare", "Custom", "Distinct", "Equals", "Explicit", "From", "Group", " By", " Join", "Into", "IsFalse", "IsTrue", "Join" _
, "Key", "Mid", "Off", "Order", "Preserve", "Skip", "Strict", "Take", "Text", "Unicode", "Until", "Where", "While", "num"}
Dim coma As Char = Chr(34)
Dim comilla As New Regex("[" & coma & "]\s*([^" & coma & "]*)")
Dim comazo As String = comilla.ToString & coma
Dim scomen As Char = "'"
Dim simcomen As New Regex("[']\s*([^']*)")
Dim scomentar As String = simcomen.ToString & vbNewLine
For num = 0 To palabrasvb.Count - 1
Buscarcoma(palabrasvb(num), rtb, Color.Blue)
Buscarcoma(palabrasvb(num), rtb2, Color.Blue)
Next
'cometarios
Buscarcoma(scomentar, rtb, Color.Firebrick)
Buscarcoma(scomentar, rtb2, Color.Firebrick)
'texto
Buscarcoma(comazo, rtb, Color.Firebrick)
Buscarcoma(comazo, rtb2, Color.Firebrick)
End Sub
' C#
Public Sub lenguajecsharp(ByVal rtb As RichTextBox, ByVal rtb2 As RichTextBox)
Dim palabrascsharp() As String = New String() {"abstract", "event", "new", "struct", "as", "explicit", "null", "switch", "base", _
"extern", "object", "this", "bool", "false", "operator", "throw", "break", "finally", " out", "true", "byte", _
"fixed", "override", "try", "case", "float", "params", "typeof", "catch", "for ", "Public", "uint", "char", _
"each", "protected", "ulong", "checked", "goto", "public", "unchecked", "class", " if ", "readonly", "unsafe", _
"const", "implicit", "ref", "ushort", "continue", " in ", "return", "using", "decimal", "int", "sbyte", "virtual", _
"default", "interface", "sealed", "volatile", "delegate", "internal", "short", "void", " do ", " is ", "sizeof", "while", _
"double", "lock", "stackalloc", "else", "long", "static", "enum", "namespace", "string", "add", "from", "get", _
"global", "group", "into", "join", " let ", "orderby", "partial", "remove", "select", "set ", "value", "var", _
"where", "yield", "Elseif"}
For j As Integer = 0 To palabrascsharp.Count - 1
Buscarcoma(palabrascsharp(j), rtb, Color.Blue)
Buscarcoma(palabrascsharp(j), rtb2, Color.Blue)
Next
End Sub
'C++
Public Sub lenguajecpp(ByVal rtb As RichTextBox, ByVal rtb2 As RichTextBox)
Dim palabracpp As String() = New String() {"__abstract", "abstract", "__alignof", "Operator", "array", "__asm", _
"__assume", "__based", "bool", "__box", "break", "case", "catch", "__cdecl", "char", "class", _
"const", "const_cast", "continue", "__declspec", "default", "__delegate", "delegate", "delete", _
"deprecated", "dllexport", "dllimport", " do ", "double", "dynamic_cast", "else", "enum", "event", _
"__event", "__except", "explicit", "extern", "false", "__fastcall", "__finally", "finally", "float", " for ", _
"each", " in ", "__forceinline", "friend", "friend_as", "__gc", "gcnew", "generic", "goto", "__hook", _
"__identifier", " if ", "_if_exists", "__if_not_exists", "initonly", "__inline", "inline", " int ", "__int8", _
"__int16", "__int32", "__int64", "__interface", "interface", "interior_ptr", "__leave", "literal", "long", "__m64", _
"__m128", "__m128d", "__m128i", "__multiple_inheritance", "mutable", "naked", "namespace", _
" new ", "__nogc", "noinline", "__noop", "noreturn", "nothrow", "novtable", "nullptr", "operator", _
"__pin", "Public", "__property", "property", "protected", "public", "__raise", " ref ", "register", "reinterpret_cast", "return", _
"safecast", "__sealed", "sealed", "selectany", "short", "signed", "__single_inheritance", "sizeof", "static", "static_cast", "__stdcall", "struct", "__super", _
"switch", "template", "this", "__thiscall", "thread", "throw", "true", "try", "__try", "__except", "__finally", "__try_cast", "typedef", "typeid", "typeid", _
"typename", "__unaligned", "__unhook", "union", "unsigned", "using", "uuid", "__uuidof", "value", "__value", "virtual", "__virtual_inheritance", "void", _
"volatile", "__w64", "__wchar_t", "wchar_t", "while"}
For j As Integer = 0 To palabracpp.Count - 1
Buscarcoma(palabracpp(j), rtb, Color.Blue)
Buscarcoma(palabracpp(j), rtb2, Color.Blue)
Next
End Sub
'PHP
Public Sub lenguajephp(ByVal rtb As RichTextBox, ByVal rtb2 As RichTextBox)
Dim palabraphp As String() = New String() {"and", " or ", "xor", "__FILE__", "exception", "__LINE__", "array", " as ", " break", "case", "class", _
"const", "continue", "declare", "default", "die", " do ", "echo", "else", "elseif", "empty", "enddeclare", "endfor", "endforeach", _
"endif", "endswitch", "endwhile", "eval", "exit", "extends", "for", "foreach", "function", "global", "if", "include", "include_once", _
"isset", "list", "new", "print", "require", "require_once", "return", "static", "switch", "unset", " use", "var", "while", _
"__FUNCTION__", "__CLASS__", "__METHOD__", "final", "php_user_filter", "interface", "implements", "extends", _
"public", "Public", "protected", "abstract", "clone", "try", "catch", "throw", "cfunction", "old_function", "this", "namespace", _
"import", "goto"}
For j As Integer = 0 To palabraphp.Count - 1
Buscarcoma(palabraphp(j), rtb, Color.Blue)
Buscarcoma(palabraphp(j), rtb2, Color.Blue)
Next
End Sub
'java
Public Sub lenguajejava(ByVal rtb As RichTextBox, ByVal rtb2 As RichTextBox)
Dim palabrajava As String() = New String() {"abstract", "default", " if ", "Public", "this", "boolean", " do ", "implements", "protected", "throw", _
"break", "double", "import", "public", "throws", "byte", "else", "instanceof", "return", "transient", "case", "extends", " int ", _
"short", "try", "catch", "final", "interface", "static", "void", "char", "finally", "long", "strictfp", "volatile", "class", "float", "native", _
"super", "while", "const", "for", "new", "switch", "continue", "goto", "package", "synchronized"}
For j As Integer = 0 To palabrajava.Count - 1
Buscarcoma(palabrajava(j), rtb, Color.Blue)
Buscarcoma(palabrajava(j), rtb2, Color.Blue)
Next
End Sub
'python
Public Sub lenguajepython(ByVal rtb As RichTextBox, ByVal rtb2 As RichTextBox)
Dim palabrapython As String() = New String() {"and", "del", " fo ", " is ", "raise", " asser", " elif", "from", "lambda", "return", "break", "else", "global", _
" not ", "try", "class", "except", " if ", " or ", "while", "continue", " exec", "import", "pass", "yield", " def", "finally", " in ", "print"}
For j As Integer = 0 To palabrapython.Count - 1
Buscarcoma(palabrapython(j), rtb, Color.Blue)
Buscarcoma(palabrapython(j), rtb2, Color.Blue)
Next
End Sub
'C pelao
Public Sub lengaujec(ByVal rtb As RichTextBox, ByVal rtb2 As RichTextBox)
Dim palabracpelao As String() = New String() {"auto", "break", "case", "char", "const", "continue", "default", " do ", "double", "else", "enum", "extern", _
"float", " for ", "goto", "if ", " int ", "long", "register", "return", "short", "signed", "sizeof", "static", "struct", "switch", "typedef", _
"union", "unsigned", "void", "volatile", "while"}
For j As Integer = 0 To palabracpelao.Count - 1
Buscarcoma(palabracpelao(j), rtb, Color.Blue)
Buscarcoma(palabracpelao(j), rtb2, Color.Blue)
Next
End Sub
End Class
crear post xml