Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #33940 > unrolled thread

parsing regular expression pattern

Started byPhilipp Kraus <philipp.kraus.flashpixx@gmail.com>
First post2016-03-08 08:17 -0800
Last post2016-03-11 13:45 -0800
Articles 6 — 3 participants

Back to article view | Back to comp.lang.java.programmer


Contents

  parsing regular expression pattern Philipp Kraus <philipp.kraus.flashpixx@gmail.com> - 2016-03-08 08:17 -0800
    Re: parsing regular expression pattern Lew <lewbloch@gmail.com> - 2016-03-08 13:26 -0800
      Re: parsing regular expression pattern Philipp Kraus <philipp.kraus.flashpixx@gmail.com> - 2016-03-08 15:12 -0800
        Re: parsing regular expression pattern Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-03-08 18:27 -0500
          Re: parsing regular expression pattern Philipp Kraus <philipp.kraus.flashpixx@gmail.com> - 2016-03-09 02:19 -0800
        Re: parsing regular expression pattern Lew <lewbloch@gmail.com> - 2016-03-11 13:45 -0800

#33940 — parsing regular expression pattern

FromPhilipp Kraus <philipp.kraus.flashpixx@gmail.com>
Date2016-03-08 08:17 -0800
Subjectparsing regular expression pattern
Message-ID<dedb82cd-3a32-458e-92ee-1dbcc7298c82@googlegroups.com>
Hello,

I have got a pattern of a regular expression and I would like to transfer the Java regex to a diagram with the JavaScript component (https://github.com/tabatkins/railroad-diagrams).
So I need to iterate over the different parts (elements, quantifiers, etc) of the regex pattern object. 

Did you have got any idea, how I can do this? I don't know how I can iterate over the regex pattern object elements.

Thanks

Phil

[toc] | [next] | [standalone]


#33941

FromLew <lewbloch@gmail.com>
Date2016-03-08 13:26 -0800
Message-ID<76180803-99c1-4561-bf86-8c0c38f9f2c7@googlegroups.com>
In reply to#33940
On Tuesday, March 8, 2016 at 8:18:01 AM UTC-8, Philipp Kraus wrote:
> Hello,
> 
> I have got a pattern of a regular expression and I would like to transfer the Java regex to a diagram with the JavaScript component (https://github.com/tabatkins/railroad-diagrams).
> So I need to iterate over the different parts (elements, quantifiers, etc) of the regex pattern object. 
> 
> Did you have got any idea, how I can do this? I don't know how I can iterate over the regex pattern object elements.

http://lmgtfy.com/?q=Java+regular+expression+parser

[toc] | [prev] | [next] | [standalone]


#33942

FromPhilipp Kraus <philipp.kraus.flashpixx@gmail.com>
Date2016-03-08 15:12 -0800
Message-ID<b573d361-e8e5-4d6b-b2b4-e5a3e9ce9df6@googlegroups.com>
In reply to#33941
Am Dienstag, 8. März 2016 22:26:42 UTC+1 schrieb Lew:
> On Tuesday, March 8, 2016 at 8:18:01 AM UTC-8, Philipp Kraus wrote:
> > Hello,
> > 
> > I have got a pattern of a regular expression and I would like to transfer the Java regex to a diagram with the JavaScript component (https://github.com/tabatkins/railroad-diagrams).
> > So I need to iterate over the different parts (elements, quantifiers, etc) of the regex pattern object. 
> > 
> > Did you have got any idea, how I can do this? I don't know how I can iterate over the regex pattern object elements.
> 
> http://lmgtfy.com/?q=Java+regular+expression+parser

Please read my first posting in detail, I don't search a "regular expression parser". I have got an Pattern object not the expression, so a pre-compiled regular expression and I would like to iterate over the parts of the pattern. 

[toc] | [prev] | [next] | [standalone]


#33943

FromEric Sosman <esosman@comcast-dot-net.invalid>
Date2016-03-08 18:27 -0500
Message-ID<nbnn03$9jj$1@dont-email.me>
In reply to#33942
On 3/8/2016 6:12 PM, Philipp Kraus wrote:
> Am Dienstag, 8. März 2016 22:26:42 UTC+1 schrieb Lew:
>> On Tuesday, March 8, 2016 at 8:18:01 AM UTC-8, Philipp Kraus wrote:
>>> Hello,
>>>
>>> I have got a pattern of a regular expression and I would like to transfer the Java regex to a diagram with the JavaScript component (https://github.com/tabatkins/railroad-diagrams).
>>> So I need to iterate over the different parts (elements, quantifiers, etc) of the regex pattern object.
>>>
>>> Did you have got any idea, how I can do this? I don't know how I can iterate over the regex pattern object elements.
>>
>> http://lmgtfy.com/?q=Java+regular+expression+parser
>
> Please read my first posting in detail, I don't search a "regular expression parser". I have got an Pattern object not the expression, so a pre-compiled regular expression and I would like to iterate over the parts of the pattern.

     Inside Pattern, the parsed form of a regex is a tree of Node's and
subclasses thereof, all of which are nested classes with java.util.regex
package-private access.  So there's no (legitimate) way to get hold of
the result of Pattern's parsing; you'll have to re-parse the regex on
your own.

     You might try to lift the parsing code from Pattern -- the whole
class is less than 6K lines, and you could discard a lot of Javadoc
and perhaps most of the actual matching code.  It could be painful to
keep up with changes to Pattern in future Java versions, though.

     Or you could write your own regex parser free-hand, accepting
a risk that it and Pattern might not agree on every corner case.

     But as far as I know, there's no legitimate way to recover the
parsed data from Pattern itself.

-- 
esosman@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM

[toc] | [prev] | [next] | [standalone]


#33945

FromPhilipp Kraus <philipp.kraus.flashpixx@gmail.com>
Date2016-03-09 02:19 -0800
Message-ID<5dfb3b13-1ad5-4fbc-bf4a-d98a002ebc11@googlegroups.com>
In reply to#33943
Am Mittwoch, 9. März 2016 00:28:09 UTC+1 schrieb Eric Sosman:
> On 3/8/2016 6:12 PM, Philipp Kraus wrote:
> > Am Dienstag, 8. März 2016 22:26:42 UTC+1 schrieb Lew:
> >> On Tuesday, March 8, 2016 at 8:18:01 AM UTC-8, Philipp Kraus wrote:
> >>> Hello,
> >>>
> >>> I have got a pattern of a regular expression and I would like to transfer the Java regex to a diagram with the JavaScript component (https://github.com/tabatkins/railroad-diagrams).
> >>> So I need to iterate over the different parts (elements, quantifiers, etc) of the regex pattern object.
> >>>
> >>> Did you have got any idea, how I can do this? I don't know how I can iterate over the regex pattern object elements.
> >>
> >> http://lmgtfy.com/?q=Java+regular+expression+parser
> >
> > Please read my first posting in detail, I don't search a "regular expression parser". I have got an Pattern object not the expression, so a pre-compiled regular expression and I would like to iterate over the parts of the pattern.
> 
>      Inside Pattern, the parsed form of a regex is a tree of Node's and
> subclasses thereof, all of which are nested classes with java.util.regex
> package-private access.  So there's no (legitimate) way to get hold of
> the result of Pattern's parsing; you'll have to re-parse the regex on
> your own.
> 
>      You might try to lift the parsing code from Pattern -- the whole
> class is less than 6K lines, and you could discard a lot of Javadoc
> and perhaps most of the actual matching code.  It could be painful to
> keep up with changes to Pattern in future Java versions, though.
> 
>      Or you could write your own regex parser free-hand, accepting
> a risk that it and Pattern might not agree on every corner case.
> 
>      But as far as I know, there's no legitimate way to recover the
> parsed data from Pattern itself.

I see this problem too, because I don't want to use reflection API to get the internal data
structures. My choice is to use AntLR to create a parser, because AntLR 4 supports
a grammar for PCRE (https://github.com/antlr/grammars-v4/blob/master/pcre/PCRE.g4).
I can run on the Pattern object toString() or pattern() and get a string representation of
the regular expression and use then the AntLR parser to get the structure back

Phil

[toc] | [prev] | [next] | [standalone]


#33947

FromLew <lewbloch@gmail.com>
Date2016-03-11 13:45 -0800
Message-ID<e9f0f26c-16a0-4862-a455-410fe184803c@googlegroups.com>
In reply to#33942
On Tuesday, March 8, 2016 at 3:12:32 PM UTC-8, Philipp Kraus wrote:
> Am Dienstag, 8. März 2016 22:26:42 UTC+1 schrieb Lew:
> > On Tuesday, March 8, 2016 at 8:18:01 AM UTC-8, Philipp Kraus wrote:
> > > Hello,
> > > 
> > > I have got a pattern of a regular expression and I would like to transfer the Java regex to a diagram with the JavaScript component (https://github.com/tabatkins/railroad-diagrams).
> > > So I need to iterate over the different parts (elements, quantifiers, etc) of the regex pattern object. 
> > > 
> > > Did you have got any idea, how I can do this? I don't know how I can iterate over the regex pattern object elements.
> > 
> > http://lmgtfy.com/?q=Java+regular+expression+parser
> 
> Please read my first posting in detail, I don't search a "regular expression parser". I have got an Pattern object not the expression, so a pre-compiled regular expression and I would like to iterate over the parts of the pattern.

Your "first posting in detail" said nothing about having a 'Pattern' object, it said you have "got a pattern of a regular expression", which does not indicate that you speak of a particular type. Case counts. I thought you meant "pattern" in the general sense.

Which does not invalidate my advice. GIYF. ("Google is your friend")

But in service of your "correction":
http://lmgtfy.com/?q=how+to+iterate+over+the+parts+of+a+java.util.regex.Pattern

-- 
Lew

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.programmer


csiph-web