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
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
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
snip
DUKE1_plateD_A12.CEL.
Thanks in advance.
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
snip
DUKE1_plateD_A12.CEL.
Thanks
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
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
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
--
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 string.
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 package body XXX
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 use it
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 return both.
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 =
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
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 but not
\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 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 effectively \b
Sweet! Thanks so much!
--
http://mail.python.org/mailman/listinfo/python-list
of which you need to handle?
Frederic
- Original Message -
From: [EMAIL PROTECTED]
Newsgroups: comp.lang.python
To: python-list@python.org
Sent: Monday, August 21, 2006 11:35 PM
Subject: Re: Regular Expression question
Hi, thanks everyone for the information! Still going through
Hi, I am having some difficulty trying to create a regular expression.
Consider:
tag1 name=john/ br/ tag2 value=adj__tall__/
tag1 name=joe/
tag1 name=jack/
tag2 value=adj__short__/
Whenever a tag1 is followed by a tag 2, I want to retrieve the values
of the tag1:name and tag2:value attributes.
[EMAIL PROTECTED] wrote:
Hi, I am having some difficulty trying to create a regular expression.
Consider:
tag1 name=john/ br/ tag2 value=adj__tall__/
tag1 name=joe/
tag1 name=jack/
tag2 value=adj__short__/
Whenever a tag1 is followed by a tag 2, I want to retrieve the values
of the
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
I am not expert of REs yet, this my first possible solution:
import re
txt =
tag1 name=john/ br/ tag2 value=adj__tall__/
tag1 name=joe/
tag1 name=jack/
tag2 value=adj__short__/
tfinder = r# The opening the tag to find
\s* # Possible space or newline
[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:
got zero results on this one :)
--
http://mail.python.org/mailman/listinfo/python-list
[EMAIL PROTECTED] wrote:
Hi, I am having some difficulty trying to create a regular expression.
Consider:
tag1 name=john/ br/ tag2 value=adj__tall__/
tag1 name=joe/
tag1 name=jack/
tag2 value=adj__short__/
Whenever a tag1 is followed by a tag 2, I want to retrieve the values
of the
[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
On 2006-08-21, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
Hi, I am having some difficulty trying to create a regular expression.
Consider:
tag1 name=john/ br/ tag2 value=adj__tall__/
tag1 name=joe/
tag1 name=jack/
tag2 value=adj__short__/
Whenever a tag1 is followed by a tag 2, I want to
[EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
Hi, I am having some difficulty trying to create a regular expression.
Consider:
tag1 name=john/ br/ tag2 value=adj__tall__/
tag1 name=joe/
tag1 name=jack/
tag2 value=adj__short__/
Whenever a tag1 is followed by a tag 2, I want
[EMAIL PROTECTED] wrote:
got zero results on this one :)
Really?
s = '''tag1 name=john/ br/ tag2 value=adj__tall__/
tag1 name=joe/
tag1 name=jack/
tag2 value=adj__short__/'''
pat = re.compile('tag1.+?name=(.+?).*?(?:)(?=tag2).*?=adj__(.*?)__',
re.DOTALL)
m = re.findall(pat, s)
m
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
Paul McGuire wrote:
import re
r=re.compile('img\s+src=(?Pimage[^]+)[^]*',re.IGNORECASE)
for m in r.finditer(html):
print m.group('image')
Ouch - this fails to match any img tag that has some other
attribute, such as height or width, before the src attribute.
www.yahoo.com has
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
[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:
I'm sorry! I mean pattern is an argument of the function, in this case,howI process special charactors. patter = 'www.'# not thisif re.compile(pattern).match(string) is not None: ..but not: if re.compile(r'www.').match(string) is not None: or if
[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 =
pyparsing is cool.
but use only re is also OK
# -*- coding: UTF-8 -*-
import urllib2
html=urllib2.urlopen(urhttp://www.yahoo.com/;).read()
import re
r=re.compile('img\s+src=(?Pimage[^]+)[^]*',re.IGNORECASE)
for m in r.finditer(html):
print m.group('image')
I got these rusults:
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(urhttp://www.yahoo.com/;).read()
import re
r=re.compile('img\s+src=(?Pimage[^]+)[^]*',re.IGNORECASE)
for m in
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
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 create ONE
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 regular
[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 01
which
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
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 forward
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 non-greedy
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)
The non-greedy is
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-greedy is actually
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 regular
[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
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' only
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 its own. The
Thank you! I had totally forgot about that. It works.
--
http://mail.python.org/mailman/listinfo/python-list
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
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
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
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
# Example 2
# This also
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
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 things
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
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
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
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
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 conventional
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:
pyimport shlex
py# fake an open record
pyimport cStringIO
pymyfakeRecord = cStringIO.StringIO()
pymyfakeRecord.write(['1','2'] \n 'fdfdfdfd'
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 only,
64 matches
Mail list logo