Cpcp Cp writes:
> Look this
>
> >>> import re
> >>> text="asdfnbd]"
> >>> m=re.sub("n*?","?",text)
> >>> print m
> ?a?s?d?f?n?b?d?]?
>
> I don't understand the 'non-greedy' pattern.
Since ‘n*’ matches zero or more ‘n’s, it matches zero adjacent to every
actual character.
It's non-greedy because
Look this
>>> import re
>>> text="asdfnbd]"
>>> m=re.sub("n*?","?",text)
>>> print m
?a?s?d?f?n?b?d?]?
I don't understand the 'non-greedy' pattern.
I think the repl argument should replaces every char in text and outputs
"".
--
https://mail.python.org/mailman/listinfo/python-list
On Oct 16, 2008, at 11:25 PM, Steve Holden wrote:
Pat wrote:
Faheem Mitha wrote:
Hi,
I need to match a string of the form
capital_letter underscore capital_letter number
against a string of the form
anything capital_letter underscore capital_letter number
some_stuff_not_starting with a nu
Pat wrote:
> Faheem Mitha wrote:
>> Hi,
>>
>> I need to match a string of the form
>>
>> capital_letter underscore capital_letter number
>>
>> against a string of the form
>>
>> anything capital_letter underscore capital_letter number
>> some_stuff_not_starting with a number
>>
>
>> DUKE1_plat
Faheem Mitha wrote:
Hi,
I need to match a string of the form
capital_letter underscore capital_letter number
against a string of the form
anything capital_letter underscore capital_letter number
some_stuff_not_starting with a number
DUKE1_plateD_A12.CEL.
Thanks in advance. Please cc
Faheem Mitha:
> I need to match a string of the form
> ...
Please, show the code you have written so far, with your input-output
examples included (as doctests, for example), and we can try to find
ways to help you remove the bugs you have.
Bye,
bearophile
--
http://mail.python.org/mailman/listin
Hi,
I need to match a string of the form
capital_letter underscore capital_letter number
against a string of the form
anything capital_letter underscore capital_letter number
some_stuff_not_starting with a number
Eg D_A1 needs to match with DUKE1_plateD_A1.CEL, but not any of
DUKE1_pla
On Oct 25, 9:25 am, Peter Otten <[EMAIL PROTECTED]> wrote:
>
> You want a "negative lookahead assertion" then:
>
Now I feel dumb...
I've seen the (?!...) dozen times in the doc but never figure out that
it is what I'm looking for.
So this one is the winner:
s = re.search(r'create\s+or\s+replace\s
looping wrote:
> On Oct 25, 8:49 am, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
>>
>> needle = re.compile(r'create\s+or\s+replace\s+package(\s+body)?\s+',
>> re.IGNORECASE)
>
> What I want here is a RE that return ONLY the line without the "body"
> keyword.
> Your RE
On Oct 25, 8:49 am, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
>
> needle = re.compile(r'create\s+or\s+replace\s+package(\s+body)?\s+',
> re.IGNORECASE)
What I want here is a RE that return ONLY the line without the "body"
keyword.
Your RE return both.
I know I could u
On Thu, 25 Oct 2007 06:34:03 +, looping wrote:
> Hi,
> It's not really a Python question but I'm sure someone could help me.
>
> When I use RE, I always have trouble with this kind of search:
>
> Ex.
>
> I've a text file:
> """
> create or replace package XXX
> ...
>
> create or replace pa
Hi,
It's not really a Python question but I'm sure someone could help me.
When I use RE, I always have trouble with this kind of search:
Ex.
I've a text file:
"""
create or replace package XXX
...
create or replace package body XXX
...
"""
now I want to search the position (line) of this two st
Sweet! Thanks so much!
--
http://mail.python.org/mailman/listinfo/python-list
unexpected wrote:
> > \b matches the beginning/end of a word (characters a-zA-Z_0-9).
> > So that regex will match e.g. MULTX-FOO but not MULTX-.
> >
>
> So is there a way to get \b to include - ?
No, but you can get the behaviour you want using negative lookaheads.
The following regex is effecti
> \b matches the beginning/end of a word (characters a-zA-Z_0-9).
> So that regex will match e.g. MULTX-FOO but not MULTX-.
>
So is there a way to get \b to include - ?
--
http://mail.python.org/mailman/listinfo/python-list
"unexpected" <[EMAIL PROTECTED]> writes:
> I'm trying to do a whole word pattern match for the term 'MULTX-'
>
> Currently, my regular expression syntax is:
>
> re.search(('^')+(keyword+'\\b')
\b matches the beginning/end of a word (characters a-zA-Z_0-9).
So that regex will match e.g. MULTX-FOO
I'm trying to do a whole word pattern match for the term 'MULTX-'
Currently, my regular expression syntax is:
re.search(('^')+(keyword+'\\b')
where keyword comes from a list of terms. ('MULTX-' is in this list,
and hence a keyword).
My regular expression works for a variety of different keyword
cases all of which you need to handle?
Frederic
- Original Message -
From: <[EMAIL PROTECTED]>
Newsgroups: comp.lang.python
To:
Sent: Monday, August 21, 2006 11:35 PM
Subject: Re: Regular Expression question
> Hi, thanks everyone for the information! Still going through it
Hi, thanks everyone for the information! Still going through it :)
The reason I did not match on tag2 in my original expression (and I
apologize because I should have mentioned this before) is that other
tags could also have an attribute with the value of "adj__" and the
attribute name may not be
[EMAIL PROTECTED] wrote:
> got zero results on this one :)
Really?
>>> s = '''
'''
>>> pat = re.compile('tag1.+?name="(.+?)".*?(?:<)(?=tag2).*?="adj__(.*?)__',
>>> re.DOTALL)
>>> m = re.findall(pat, s)
>>> m
[('john', 'tall'), ('joe', 'short')]
Regards,
Rob
--
http://mail.python.org/m
<[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Hi, I am having some difficulty trying to create a regular expression.
>
> Consider:
>
>
>
>
>
>
> Whenever a tag1 is followed by a tag 2, I want to retrieve the values
> of the tag1:name and tag2:value attributes. So my end resul
On 2006-08-21, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> Hi, I am having some difficulty trying to create a regular expression.
>
> Consider:
>
>
>
>
>
>
> Whenever a tag1 is followed by a tag 2, I want to retrieve the
> values of the tag1:name and tag2:value attributes. So my end
> result
[EMAIL PROTECTED] wrote:
> Hi, I am having some difficulty trying to create a regular expression.
Steve,
I find this tool is great for debugging regular expressions.
http://kodos.sourceforge.net/
Just put some sample text in one window, your trial RE in another, and
Kodos displays a wealth of
[EMAIL PROTECTED] wrote:
> Hi, I am having some difficulty trying to create a regular expression.
>
> Consider:
>
>
>
>
>
>
> Whenever a tag1 is followed by a tag 2, I want to retrieve the values
> of the tag1:name and tag2:value attributes. So my end result here
> should be
> john, tal
got zero results on this one :)
--
http://mail.python.org/mailman/listinfo/python-list
[EMAIL PROTECTED] wrote:
> Thanks, i just tried it but I got the same result.
>
> I've been thinking about it for a few hours now and the problem with
> this approach is that the .*? before the (?=tag2) may have matched a
> tag1 and i don't know how to detect it.
Maybe like this:
'tag1.+?name="(.
I am not expert of REs yet, this my first possible solution:
import re
txt = """
"""
tfinder = r"""<# The opening < the tag to find
\s* # Possible space or newline
(tag[12]) # First subgroup, the identifier, tag1
or tag2
Thanks, i just tried it but I got the same result.
I've been thinking about it for a few hours now and the problem with
this approach is that the .*? before the (?=tag2) may have matched a
tag1 and i don't know how to detect it.
And even if I could, how would I make the search reset its start
pos
[EMAIL PROTECTED] wrote:
> Hi, I am having some difficulty trying to create a regular expression.
>
> Consider:
>
>
>
>
>
>
> Whenever a tag1 is followed by a tag 2, I want to retrieve the values
> of the tag1:name and tag2:value attributes. So my end result here
> should be
> john, tall
>
Hi, I am having some difficulty trying to create a regular expression.
Consider:
Whenever a tag1 is followed by a tag 2, I want to retrieve the values
of the tag1:name and tag2:value attributes. So my end result here
should be
john, tall
jack, short
My low quality regexp
re.compile('tag1
Paul McGuire wrote:
>> import re
>> r=re.compile('[^"]+)"[^>]*>',re.IGNORECASE)
>> for m in r.finditer(html):
>> print m.group('image')
>>
>
> Ouch - this fails to match any tag that has some other
> attribute, such as "height" or "width", before the "src" attribute.
> www.yahoo.com has sev
"Frank Potter" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> pyparsing is cool.
> but use only re is also OK
> # -*- coding: UTF-8 -*-
> import urllib2
> html=urllib2.urlopen(ur"http://www.yahoo.com/";).read()
>
> import re
> r=re.compile('[^"]+)"[^>]*>',re.IGNORECASE)
> for m in r.
pyparsing is cool.
but use only re is also OK
# -*- coding: UTF-8 -*-
import urllib2
html=urllib2.urlopen(ur"http://www.yahoo.com/";).read()
import re
r=re.compile('[^"]+)"[^>]*>',re.IGNORECASE)
for m in r.finditer(html):
print m.group('image')
I got these rusults:
http://us.i1.yimg.com/us.yi
<[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Hi,
> I am new to python regular expression, I would like to use it to get an
> attribute of an html element from an html file?
>
> for example, I was able to read the html file using this:
>req = urllib2.Request(url=acaURL)
> f
I'm sorry! I mean pattern is an argument of the function, in this case, how I process special charactors. patter = 'www.' # not this if re.compile(pattern).match(string) is not None: .. but not: if re.compile(r'www.').match(string) is not None
[EMAIL PROTECTED] wrote:
> I am new to python regular expression, I would like to use it to get an
> attribute of an html element from an html file?
if you want to parse HTML, use an HTML parser. if you want to parse
sloppy HTML, use a tolerant HTML parser:
http://www.crummy.com/software/
Hi,
I am new to python regular expression, I would like to use it to get an
attribute of an html element from an html file?
for example, I was able to read the html file using this:
req = urllib2.Request(url=acaURL)
f = urllib2.urlopen(req)
data = f.read()
my question is how can I jus
Michelle McCall wrote:
>I have a script that needs to scan every line of a file for numerous
> strings. There are groups of strings for each "area" of data we are looking
> for. Looping through each of these list of strings separately for each line
> has slowed execution to a crawl. Can I creat
I have a script that needs to scan every line of a file for numerous
strings. There are groups of strings for each "area" of data we are looking
for. Looping through each of these list of strings separately for each line
has slowed execution to a crawl. Can I create ONE regular expression from a
On Mon, 7 Nov 2005 16:38:11 -0800, James Stroud <[EMAIL PROTECTED]> wrote:
>On Monday 07 November 2005 16:18, [EMAIL PROTECTED] wrote:
>> Ya, for some reason your non-greedy "?" doesn't seem to be taking.
>> This works:
>>
>> re.sub('(.*)(00.*?01) target_mark', r'\2', your_string)
>
>The non-greed
On Monday 07 November 2005 17:31, Kent Johnson wrote:
> James Stroud wrote:
> > On Monday 07 November 2005 16:18, [EMAIL PROTECTED] wrote:
> >>Ya, for some reason your non-greedy "?" doesn't seem to be taking.
> >>This works:
> >>
> >>re.sub('(.*)(00.*?01) target_mark', r'\2', your_string)
> >
> >
James Stroud wrote:
> On Monday 07 November 2005 16:18, [EMAIL PROTECTED] wrote:
>
>>Ya, for some reason your non-greedy "?" doesn't seem to be taking.
>>This works:
>>
>>re.sub('(.*)(00.*?01) target_mark', r'\2', your_string)
>
>
> The non-greedy is actually acting as expected. This is because
On Monday 07 November 2005 16:18, [EMAIL PROTECTED] wrote:
> Ya, for some reason your non-greedy "?" doesn't seem to be taking.
> This works:
>
> re.sub('(.*)(00.*?01) target_mark', r'\2', your_string)
The non-greedy is actually acting as expected. This is because non-greedy
operators are "forwar
Ya, for some reason your non-greedy "?" doesn't seem to be taking.
This works:
re.sub('(.*)(00.*?01) target_mark', r'\2', your_string)
--
http://mail.python.org/mailman/listinfo/python-list
[EMAIL PROTECTED] wrote:
> Hi,
>
> I'm having trouble extracting substrings using regular expression. Here
> is my problem:
>
> Want to find the substring that is immediately before a given
> substring. For example: from
> "00 noise1 01 noise2 00 target 01 target_mark",
> want to get
> "00 target
Hi,
I'm having trouble extracting substrings using regular expression. Here
is my problem:
Want to find the substring that is immediately before a given
substring. For example: from
"00 noise1 01 noise2 00 target 01 target_mark",
want to get
"00 target 01"
which is before
"target_mark".
My regula
Thank you! I had totally forgot about that. It works.
--
http://mail.python.org/mailman/listinfo/python-list
On 14 Jun 2005 04:01:58 -0700, rumours say that "[EMAIL PROTECTED]"
<[EMAIL PROTECTED]> might have written:
>I want to match a word against a string such that 'peter' is found in
>"peter bengtsson" or " hey peter," or but in "thepeter bengtsson" or
>"hey peterbe," because the word has to stand on
On Tue, 14 Jun 2005 13:01:58 +0200, [EMAIL PROTECTED] wrote
(in article <[EMAIL PROTECTED]>):
> How do I modify my regular expression to match on expressions as well
> as just single words??
import re
def createStandaloneWordRegex(word):
""" return a regular expression that can find 'peter'
[EMAIL PROTECTED] wrote:
> I want to match a word against a string such that 'peter' is found in
> "peter bengtsson" or " hey peter," or but in "thepeter bengtsson" or
> "hey peterbe," because the word has to stand on its own. The following
> code works for a single word:
>
> def createStandaloneW
I want to match a word against a string such that 'peter' is found in
"peter bengtsson" or " hey peter," or but in "thepeter bengtsson" or
"hey peterbe," because the word has to stand on its own. The following
code works for a single word:
def createStandaloneWordRegex(word):
""" return a regu
Bruno Desthuilliers wrote:
>> match = STX + '(.*)' + ETX
>>
>> # Example 1
>> # This appears to work, but I'm not sure if the '+' is being used in
>> the regular expression, or if it's just joining STX, '(.*)', and ETX.
>>
>> if re.search(STX + '(.*)' + ETX,data):
>> print "Matches"
>>
>> # Exam
> You may want something like:
> if re.search('%s(.*)%s' % (STX, ETX), data):
>
Ah I didn't even think about that...
Chris
--
http://mail.python.org/mailman/listinfo/python-list
snacktime a écrit :
The primary question is how do I perform a match when the regular
expression contains string variables? For example, in the following
code I want to match a line that starts with STX, then has any number
of characters, then ends with STX.
Example 2 I'm pretty sure works as I ex
The primary question is how do I perform a match when the regular
expression contains string variables? For example, in the following
code I want to match a line that starts with STX, then has any number
of characters, then ends with STX.
Example 2 I'm pretty sure works as I expect, but I'm not su
John Machin wrote:
André Roberge wrote:
Sorry for the simple question, but I find regular
expressions rather intimidating. And I've never
needed them before ...
How would I go about to 'define' a regular expression that
would identify strings like
__alphanumerical__ as in __init__
(Just to spell
André Roberge wrote:
> Sorry for the simple question, but I find regular
> expressions rather intimidating. And I've never
> needed them before ...
>
> How would I go about to 'define' a regular expression that
> would identify strings like
> __alphanumerical__ as in __init__
> (Just to spell th
Sorry for the simple question, but I find regular
expressions rather intimidating. And I've never
needed them before ...
How would I go about to 'define' a regular expression that
would identify strings like
__alphanumerical__ as in __init__
(Just to spell things out, as I have seen underscores d
Oops!
Sorry, didn't realize that.
Thanks,
"M.E.Farmer" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
>
> It's me wrote:
> > The shlex.py needs quite a number of .py files. I tried to hunt down
> a few
> > of them and got really tire.
> >
> > Is there one batch of .py files that I
It's me wrote:
> The shlex.py needs quite a number of .py files. I tried to hunt down
a few
> of them and got really tire.
>
> Is there one batch of .py files that I can download from somewhere?
>
> Thanks,
Not sure what you mean by this.
Shlex is a standard library module.
It imports os and sys
The shlex.py needs quite a number of .py files. I tried to hunt down a few
of them and got really tire.
Is there one batch of .py files that I can download from somewhere?
Thanks,
"M.E.Farmer" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Hello me,
> Have you tried shlex.py it
Hello me,
Have you tried shlex.py it is a tokenizer for writing lexical
parsers.
Should be a breeze to whip something up with it.
an example of tokenizing:
py>import shlex
py># fake an open record
py>import cStringIO
py>myfakeRecord = cStringIO.StringIO()
py>myfakeRecord.write("['1','2'] \n 'fdfdfd
I'll chew on this. Thanks, got to go.
"Steve Holden" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> It's me wrote:
>
> > I am never very good with regular expressions. My head always hurts
> > whenever I need to use it.
> >
> Well, they are a pain to more than just you, and the c
check jgsoft dot com, they have2 things witch may help. Edit pad pro
(the test version has a good tutorial) or power grep (if you do a lot
of regexes, or the mastering regular expressions book from Orielly (if
yo do a lot of regex work)
Also the perl group would be good for regexes (pythons are P
It's me wrote:
I am never very good with regular expressions. My head always hurts
whenever I need to use it.
Well, they are a pain to more than just you, and the conventional advice
is "even when you are convinced you need to use REs, try and find
another way".
I need to read a data file and p
I am never very good with regular expressions. My head always hurts
whenever I need to use it.
I need to read a data file and parse each data record. Each item on the
data record begins with either a string, or a list of strings. I searched
around and didn't see any existing Python packages tha
66 matches
Mail list logo