ANTLR or Regex?

I write CMS in ASP.NET/C#, and I need to handle such things, every request to a page:

<html>
<head>
    <title>[Title]</title>
</head>
<body>
    <form action="[Action]" method="get">
        [TextBox Name="Email", Background=Red]
        [Button Type="Submit"]
    </form>
</body>
</html>

and, of course, replace [...].

My question is how to implement it, with ANTLR or with Regex? What will be faster? Please note that if I implement it with ANTLR, I think that I will need to implement XML by adding to [..].

I will need to implement the parameters, etc.

EDIT: Note that my regex might even look something like this:

public override string ToString()
{
    return Regex.Replace(Input, @"\[
                                    \s*(?<name>\w+)\s*
                                    (?<parameter>
                                        [\s,]*
                                            (?<paramName>\w+)
                                            \s*
                                            =
                                            \s*
                                            (
                                                (?<paramValue>\w+)
                                                |
                                                (""(?<paramValue>[^""]*)"")
                                            )
                                    )*
                               \]", (match) =>
                                  {
                                      ...
                                  }, RegexOptions.IgnorePatternWhitespace);
}        
+3
source share
3 answers

RegEx ANTLR - . " " , .

RegEx - . , , , . , , RegEx. Expresso, .

ANTLR - . , , .

, / XML, XPath? .

, , . - . ? , , , , .

, !

+4

ANTLR RegEx RegEx #. , , ANTLR .

ANTLR , XML. [ ] .

RegEx ANTLR ( " ..", ).

: RegEx , . - RegEx RegEx. (Google @ regex gskinner)

ANTLR " ": / . RegEx .

RegEx : RegEx , [... ] . "..." , RegEx ( ). , .

+1

, , , , , . , ANTLR . , XML .

0

Source: https://habr.com/ru/post/1735600/


All Articles