tags:

views:

199

answers:

3

I am interested in parsing regexes (not to be confused with using regexes for parsing). Is there a BNF for Java 1.6 regexes (or other languages?)

[NOTE: There is a similar older question which did not lead to an answer for Java.]

EDIT To explain why I need to do this. We are implementing a shallow parser for Natural language processing which first identifies and tags tokens. These are then further processed with a regex. I need to know what groups have been captured by the regex (the automaton only captures the last of each bracket) and I also want to annotate the regex with comments.

+3  A: 

Here they point to attempts at describing Perl's regexes in BNF:

http://www.cs.sfu.ca/~cameron/Teaching/384/99-3/regexp-plg.html

http://www.faqts.com/knowledge%5Fbase/view.phtml/aid/25718/fid/200

Vinko Vrsalovic
http://www.faqts.com/knowledge%5Fbase/view.phtml/aid/25718/fid/200 doesn't work for me
Makach
@Makach: Replace `%5F` with `_`. SO seems to replace that in URLs.
Gumbo
+1  A: 

I don't see one specifically for java 1.6; but here's a start that maybe you can build a complete BNF from:

http://www.users.pjwstk.edu.pl/~jms/qnx/help/watcom/wd/regexp.html#RegularExpressionBNF

...using the java 1.6 documentation for Pattern:

http://java.sun.com/javase/6/docs/api/java/util/regex/Pattern.html

RMorrisey
Also you should be aware, if you weren't already, that the JDK has support for regular expressions (see the Pattern class linked in this post) - be sure you aren't reinventing the wheel.
RMorrisey
Disregard last comment
RMorrisey
A: 

There does not seem to be an explicit regex according to SO replies.

peter.murray.rust