Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #33943
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: parsing regular expression pattern |
| Date | 2016-03-08 18:27 -0500 |
| Organization | A noiseless patient Spider |
| Message-ID | <nbnn03$9jj$1@dont-email.me> (permalink) |
| References | <dedb82cd-3a32-458e-92ee-1dbcc7298c82@googlegroups.com> <76180803-99c1-4561-bf86-8c0c38f9f2c7@googlegroups.com> <b573d361-e8e5-4d6b-b2b4-e5a3e9ce9df6@googlegroups.com> |
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
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
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
csiph-web