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 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>
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
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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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.
...
|
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...
|
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...
|
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
...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
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...
|
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...
|
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,...
|
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...
|
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,...
|
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...
|
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...
| |