Not specific to Python, but it will be implemented in it... how do I
compile a RE to catch everything between two know values? Here's what
I've tried (but failed) to accomplish... the knowns here are START and
END:
data = "asdfasgSTARTpruyerfghdfjENDhfawrgbqfgsfgsdfg"
x = re.compile('START.END', re.DOTALL)
x.findall(data) 9 1118
data = "asdfasgSTARTpruyerfghdfjENDhfawrgbqfgsfgsdfg"
x = re.compile('START.END', re.DOTALL)
This should work:
x = re.compile('START(.*)END', re.DOTALL)
On Sep 21, 2:44 pm, David <wizza...@gmail.comwrote:
data = "asdfasgSTARTpruyerfghdfjENDhfawrgbqfgsfgsdfg"
x = re.compile('START.END', re.DOTALL)
This should work:
x = re.compile('START(.*)END', re.DOTALL)
You'll want to use a non-greedy match:
x = re.compile(r"START(.*?)END", re.DOTALL)
Otherwise the . will match END as well. ch************@gmail.com wrote:
On Sep 21, 2:44 pm, David <wizza...@gmail.comwrote:
>>data = "asdfasgSTARTpruyerfghdfjENDhfawrgbqfgsfgsdfg" x = re.compile('START.END', re.DOTALL)
This should work:
x = re.compile('START(.*)END', re.DOTALL)
You'll want to use a non-greedy match:
x = re.compile(r"START(.*?)END", re.DOTALL)
Otherwise the . will match END as well.
Only if there's a later END in the string, in which case the user's
requirements will determine whether greedy matching is appropriate.
regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
Sorry, the dog ate my .sigline
You'll want to use a non-greedy match:
x = re.compile(r"START(.*?)END", re.DOTALL)
Otherwise the . will match END as well.
On Sep 21, 3:23 pm, Steve Holden <st...@holdenweb.comwrote:
Only if there's a later END in the string, in which case the user's
requirements will determine whether greedy matching is appropriate.
regards
Steve
There will be lots of START END combinations in the data. This is more
accurate:
sfgdfg*START*dfhdgh*END*dfdgh*START*dfhfdgh*END*df gsdh*START*sdfhfdhj*END*fdghfdj
The RE should extract the data between each couples of START and END.
Thanks!
On Fri, Sep 21, 2007 at 12:05:51PM -0700, ch************@gmail.com wrote regarding Re: RE Help:
>
x = re.compile('START(.*)END', re.DOTALL)
You'll want to use a non-greedy match:
x = re.compile(r"START(.*?)END", re.DOTALL)
Otherwise the . will match END as well.
The . will only consume END if there is another END to match later on in the string. And then it's a question of desired fuctionality. If the given string is: "abcdSTARTefgENDxyzENDhijk" do you want to match "STARTefgEND" (in which case you need a non-greedy match r".*?" )? or do you want to match "STARTefgENDxyzEND" (in which case you need a greedy match: r".*" )?
Cheers,
Cliff
On Sep 21, 3:32 pm, byte8b...@gmail.com wrote:
You'll want to use a non-greedy match:
x = re.compile(r"START(.*?)END", re.DOTALL)
Otherwise the . will match END as well.
On Sep 21, 3:23 pm, Steve Holden <st...@holdenweb.comwrote:
Only if there's a later END in the string, in which case the user's
requirements will determine whether greedy matching is appropriate.
regards
Steve
There will be lots of START END combinations in the data. This is more
accurate:
sfgdfg*START*dfhdgh*END*dfdgh*START*dfhfdgh*END*df gsdh*START*sdfhfdhj*END*fdghfdj
The RE should extract the data between each couples of START and END.
Thanks!
You'll want to use my version then. Glad to help!
On Friday 21 September 2007, by*******@gmail.com wrote:
Not specific to Python, but it will be implemented in it... how do I
compile a RE to catch everything between two know values? Here's what
I've tried (but failed) to accomplish... the knowns here are START and
END:
data = "asdfasgSTARTpruyerfghdfjENDhfawrgbqfgsfgsdfg"
x = re.compile('START.END', re.DOTALL)
x.findall(data)
I'm not sure finding a variable number of occurences can be done with re. How
about
# data = the string
strings = []
for s in data.split('START')[1:]:
strings.append(s.split('END')[0])
On Sep 21, 4:09 pm, Thomas Jollans <tho...@jollans.comwrote:
On Friday 21 September 2007, byte8b...@gmail.com wrote:
Not specific to Python, but it will be implemented in it... how do I
compile a RE to catch everything between two know values? Here's what
I've tried (but failed) to accomplish... the knowns here are START and
END:
data = "asdfasgSTARTpruyerfghdfjENDhfawrgbqfgsfgsdfg"
x = re.compile('START.END', re.DOTALL)
x.findall(data)
I'm not sure finding a variable number of occurences can be done with re. How
about
# data = the string
strings = []
for s in data.split('START')[1:]:
strings.append(s.split('END')[0])
use re.findall :-)
Thomas Jollans wrote:
On Friday 21 September 2007, by*******@gmail.com wrote:
>Not specific to Python, but it will be implemented in it... how do I compile a RE to catch everything between two know values? Here's what I've tried (but failed) to accomplish... the knowns here are START and END:
data = "asdfasgSTARTpruyerfghdfjENDhfawrgbqfgsfgsdfg" x = re.compile('START.END', re.DOTALL)
x.findall(data)
I'm not sure finding a variable number of occurences can be done with re. How
about
# data = the string
strings = []
for s in data.split('START')[1:]:
strings.append(s.split('END')[0])
Nice. I've noticed that since I switched from Perl to Python, I hardly
ever use regular expressions anymore. In perl, they're so easy to fire
up that they become the first tool out of the toolbox, but when you make
the barrier to access just a tiny bit higher (import re/re.compile) you
start noticing how easy it is to accomplish most of those feats without
regexes, and much more readably, too.
Of course, it should be noted that the different implementations
suggested behave differently, which could also affect the choice of
method. If you have "abcSTARTdefSTARTghiEND", your version will spit
out strings = ['def', 'ghi'], but a regex, depending on whether it is
greedy or non greedy, will either spit out ['STARTdefSTARTghiEND'] or
['STARTghiEND'].
Correction, it will spit out the first one, whether greedy or not. The
difference comes with two END tags in a row.
Cheers,
Cliff This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Dave |
last post by:
After following Microsofts admonition to reformat my system before doing a
final compilation of my app I got many warnings/errors upon compiling an rtf
file created in word. I used the Help...
|
by: Tom |
last post by:
A question for gui application programmers. . .
I 've got some GUI programs, written in Python/wxPython, and I've got
a help button and a help menu item. Also, I've got a compiled file
made with...
|
by: wukexin |
last post by:
Help me, good men. I find mang books that introduce bit "mang header
files",they talk too bit,in fact it is my too fool, I don't learn it, I have
do a test program, but I have no correct doing...
|
by: Colin J. Williams |
last post by:
Python advertises some basic service:
C:\Python24>python
Python 2.4.1 (#65, Mar 30 2005, 09:13:57) on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
With...
|
by: Corepaul |
last post by:
Missing Help Files
When I enter "recordset" as the keyword and search the Visual Basic Help index,
I get many topics of interest in the resulting list. But there isn't any
information available...
|
by: Steve |
last post by:
I have written a help file (chm) for a DLL and referenced it using Help.ShowHelp
My expectation is that a developer using my DLL would be able to access this help file during his development time...
|
by: Mark |
last post by:
I have loaded Visual Studio .net on my home computer and my laptop, but my
home computer has an abbreviated help screen not 2% of the help on my laptop.
All the settings look the same on both...
|
by: JonathanOrlev |
last post by:
Hello everybody,
I wrote this comment in another message of mine, but decided to post it
again as a standalone message.
I think that Microsoft's Office 2003 help system is horrible, probably...
|
by: trunxnirvana007 |
last post by:
'UPGRADE_WARNING: Array has a new behavior. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"'
'UPGRADE_WARNING: Couldn't resolve...
|
by: hitencontractor |
last post by:
I am working on .NET Version 2003 making an SDI application that calls MS Excel 2003.
I added a menu item called "MyApp Help" in the end of the menu bar to show Help-> About.
The application...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: Mushico |
last post by:
How to calculate date of retirement from date of birth
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
|
by: giovanniandrean |
last post by:
The energy model is structured as follows and uses excel sheets to give input data:
1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
|
by: Teri B |
last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course.
0ne-to-many. One course many roles.
Then I created a report based on the Course form and...
|
by: nia12 |
last post by:
Hi there,
I am very new to Access so apologies if any of this is obvious/not clear.
I am creating a data collection tool for health care employees to complete. It consists of a number of...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
|
by: isladogs |
last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, Mike...
| |