How can we convert regular expression to ANTLR 4 Expression

684 views Asked by At

I was searching for a way or tool to convert the regular expression into the ANTLR 4 expression but could not find anything suitable. Now i'm curious "Can we actually convert it or not." If not, then i assume ANTLR 4 expression and regular expression looks same look-wise but are totally different. Please correct if I'm wrong.

1

There are 1 answers

0
Lucas Trzesniewski On BEST ANSWER

ANTLR lexer rules are actually regular expressions, in the formal sense. This means you won't get pattern matching features like lookahead/lookbehind/captures etc out of the box. You can insert custom code in the rules if you need more control over the matching process.

As for the syntax, it's a bit different from the standard regex syntax.
For instance, in ANTLR you write ~[a-z] instead of [^a-z]