Expanding regexps

  • Thread starter Klaus Alexander Seistrup
  • Start date
K

Klaus Alexander Seistrup

Fredrik said:
hint:

import sre_parse
print sre_parse.parse(rx)

the rest is just a small matter of programming.

I'm not sure it's just a small matter of programming for me, as I
will have to deduce what the notation means (is there a sre_parse
tutorial somewhere?), but thanks for the hint anyway, I'll try and
see if I can make something useful out of the output.


// Klaus

--
 
D

Diez B. Roggisch

Hi,
Is there a way to "expand" simple regexps? Something along the
lines of:

What would you expect to be the result of this rex:

r'a*'

?

The language accepted by this is of unlimited size - where do you stop?
Besides, whatever you do, its a matter of non-deterministic programming,
which can be accomplished by using backtracking - but for the price of
exponential time.

Regards,

Diez
 
K

Klaus Alexander Seistrup

Diez said:
What would you expect to be the result of this rex:

r'a*'

?

The language accepted by this is of unlimited size - where do
you stop?

That's why I wrote "simple regexps", I'm fully aware that it would
be very difficult to expand all possible patterns - and that's not
what I need.

But to answer your question, even though it was probably rhetorical,
sre_parse looks at it from this angle:

#v+
import sre_parse
sre_parse.parse(r'a*') [('max_repeat', (0, 65535, [('literal', 97)]))]
#v-

// Klaus

--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top