473,406 Members | 2,352 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Expanding regexps

Hi,

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

#v+
rx = '(a|b)c?(d|f)'
expand_regexp(rx) ['ad', 'af', 'acd', 'acf', 'bd', 'bf', 'bcd', 'bcf']

#v-

Cheers,

// Klaus

--<> unselfish actions pay back better

Jul 18 '05 #1
5 1646
Klaus Alexander Seistrup wrote:
Is there a way to "expand" simple regexps? Something along the
lines of:

#v+
rx = '(a|b)c?(d|f)'
expand_regexp(rx) ['ad', 'af', 'acd', 'acf', 'bd', 'bf', 'bcd', 'bcf']


#v-


hint:

import sre_parse
print sre_parse.parse(rx)

the rest is just a small matter of programming.

</F>


Jul 18 '05 #2
Fredrik Lundh wrote:
Is there a way to "expand" simple regexps?
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

--<> unselfish actions pay back better

Jul 18 '05 #3
>> import sre_parse
print sre_parse.parse(rx)

the rest is just a small matter of programming.


Klaus> I'm not sure it's just a small matter of programming for me...

http://wombat.doc.ic.ac.uk/foldoc/foldoc.cgi?SMOP

Skip

Jul 18 '05 #4
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
Jul 18 '05 #5
Diez B. Roggisch wrote:
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?


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

--<> unselfish actions pay back better

Jul 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: R. Tarazi | last post by:
Hello together, I'm having extreme difficulties using RegExps for a specific problem and would really appreciate any help and hope somebody will read through my "long" posting... 1. <?php...
4
by: Magnus Lie Hetland | last post by:
Hi! I've been looking at ways of dealing with nested structures in regexps (becuase I figured that would be faster than the Python parsing code I've currently got) and came across a few...
1
by: Jeffrey Kilpatrick | last post by:
I have a SQL 6.5 database that we parse some data into everyday using an access program. All this was devises and setup by a programmer that I can't get in contact with anymore and it has actually...
4
by: David | last post by:
It's sad to say, but when using the AOL web site, like to send an email, they have a nifty capability such that when a window is resized, the textarea where the message is input expands not only...
1
by: Bhiksha Raj | last post by:
Hi, I created an expanding menu on one of the frames in my webpage using code I got from http://www.dynamicdrive.com/dynamicindex1/navigate1.htm I have embedded the code (with minor...
6
by: Jack | last post by:
Hello, I would like some advice on how to disable the behavior of treeviews to expand and collapse when double clicked upon, but still allow the user to use the plus and minus on each node. ...
4
by: possibilitybox | last post by:
I'm trying to make a unicode friendly regexp to grab sentences reasonably reliably for as many unicode languages as possible, focusing on european languages first, hence it'd be useful to be able...
2
by: Yorian | last post by:
I just started to try regexps in php and I didn't have too many problems, however I found a few when trying to build a templte engine. The first one is found is the dollar sign. In my template I...
13
Chrisjc
by: Chrisjc | last post by:
I am in need of an expanding and collapsing code… The goal is To be able to click a PICTURE IMAGE and expand to show information Reason for this is I have 3 TABLES of information of about ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.