Hi,
Is there a way to "expand" simple regexps? Something along the
lines of:
#v+ rx = '(a|b)c?(d|f)' expand_regexp(r x)
['ad', 'af', 'acd', 'acf', 'bd', 'bf', 'bcd', 'bcf']
#v-
Cheers,
// Klaus
--<> unselfish actions pay back better 5 1660
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(r x) ['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
// Find all blocks containing the postal code, a minimum of 50
characters and a maximum of 200 characters before and after.
|
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 interesting things...
First there is this, mentioning the (?<DEPTH>) and (?<-DEPTH>)
constructs of the .NET regexp matcher:
http://www.rassoc.com/gregr/weblog/archive.aspx?post=590
|
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 run for about
five years without a hickup! But just a few days ago our parsing
program just stops dead before completing and I did get this error
message.
"exportaLLdataToSQLifnoerror(): number 3146 Description- odbd- call
failed. Can't...
|
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
horizontally, but also vertically, to fill the space.
I took a look at their javascripts, but they are quite complex and
convoluted since they make use of many of their own functions designed
to work with their web site.
Does anybody have a...
|
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 modification to point
to my links) into a frame on my webpage.
The problem is that when I open the page on netscape 7,
| |
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.
Thanks in advance!
Jack
|
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 to refer
to any uppercase unicode character instead of just the typical ,
which doesn't include, for example É. Is there a way to do this, or
do I have to stick with using the isupper method of the string class?
|
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 would like
to write this:
{$var} where var ofcourse will be replaced by the real var however I'm
having trouble with the dollar sign I do escape the it though, my
regexp:
|
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
400x200… that I want to be able to expand to how much information I put in them…. Just need a code that will cut it off and then OPEN it…
So
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |