Unclosed character class next to nnn

I borrow a rather complex regular expression from some PHP Textile implementations (open source, properly attributed) for a simple, not quite complete Java implementation, textile4j, which I port to github and sync with Maven central (the original code was written to provide a plugin for blojsom, a Java blogging platform, which is part of a larger effort to make blojsom dependencies available in Maven Central).

Unfortunately, textile expression expressions (while they work in context preg_replace_callbackin PHP) fail in Java with the following exception:

java.util.regex.PatternSyntaxException: Unclosed character class near index 217

The statement is obvious, the decision is elusive.

Here's the raw multiline regular expression from the PHP implementation:

return preg_replace_callback('/
    (^|(?<=[\s>.\(])|[{[]) # $pre
    "                      # start
    (' . $this->c . ')     # $atts
    ([^"]+?)               # $text
    (?:\(([^)]+?)\)(?="))? # $title
    ":
    ('.$this->urlch.'+?)   # $url
    (\/)?                  # $slash
    ([^\w\/;]*?)           # $post
    ([\]}]|(?=\s|$|\)))
    /x',callback,input);

, , " ", , echo, :

(^|(?<=[\s>.\(])|[{[])"((?:(?:\([^)]+\))|(?:\{[^}]+\})|(?:\[[^]]+\])|(?:\<(?!>)|(?<!<)\>|\<\>|\=|[()]+(?! )))*)([^"]+?)(?:\(([^)]+?)\)(?="))?":([\w"$\-_.+!*'(),";\/?:@=&%#{}|\^~\[\]`]+?)(\/)?([^\w\/;]*?)([\]}]|(?=\s|$|\)))

, , -, RegExr gskinner RegexPlanet. .

, - , .

?

, PHP , , , " " RegExr, Java PHP, .

#title :

        (?:\(([^)]+?)\)(?="))? # $title
        ...^
        (?:(\([^)]+?)\)(?="))? # $title
        ....^

,

edit: Java String ( ) Textile, RegexPlanet...

"(^|(?<=[\\s>.\\(])|[{[])\"((?:(?:\\([^)]+\\))|(?:\\{[^}]+\\})|(?:\\[[^]]+\\])|(?:\\<(?!>)|(?<!<)\\>|\\<\\>|\\=|[()]+(?! )))*)([^\"]+?)(?:\\(([^)]+?)\\)(?=\"))?\":([\\w\"$\\-_.+!*'(),\";\\/?:@=&%#{}|\\^~\\[\\]`]+?)(\\/)?([^\\w\\/;]*?)([\\]}]|(?=\\s|$|\\)))"
+5
2

@CodeJockey : , . []] [^]] , ] , ^, Java unescaped [ .

, , PHP. /, , . Java- :

"(^|(?<=[\\s>.(])|[{\\[])\"((?:(?:\\([^)]+\\))|(?:\\{[^}]+\\})|(?:\\[[^]]+\\])|(?:<(?!>)|(?<!<)>|<>|=|[()]+(?! )))*)([^\"]+?)(?:\\(([^)]+?)\\)(?=\"))?\":([\\w\"$_.+!*'(),\";/?:@=&%#{}|^~\\[\\]`-]+?)(/)?([^\\w/;]*?)([]}]|(?=\\s|$|\\)))"

, , , .

+9

, , :

Java ( , Java) [ ( ]) .

, Java:

(^|(?<=[\s>.\(])|[{\[]) # $pre
"                       # start
(' . $this->c . ')      # $atts
([^"]+?)                # $text
(?:\(([^)]+?)\)(?="))?  # $title
":
('.$this->urlch.'+?)    # $url
(\/)?                   # $slash
([^\w\/;]*?)            # $post
([\]}]|(?=\s|$|\)))
/x

, , , [a-z,;[\]+-], " a - z, , , , ", [a-z,;\[\]+-] ( [ \)

Java , .

+1

All Articles