On Tue, Apr 28, 2009 at 4:03 AM, Kelie wrote:
> Hello,
>
> The following code returns 'abc123abc45abc789jk'. How do I revise the pattern
> so
> that the return value will be 'abc789jk'? In other words, I want to find the
> pattern 'abc' that is closest to 'jk'. Here the string '123', '45' and '78
2009/4/28 Marek spociń...@go2.pl,Poland :
>> import re
>> s = 'abc123abc45abc789jk'
>> p = r'abc.+jk'
>> lst = re.findall(p, s)
>> print lst[0]
>
> I suggest using r'abc.+?jk' instead.
>
> the additional ? makes the preceeding '.+' non-greedy so instead of matching
> as long string as it can it m
spir free.fr> writes:
> To avoid that, use non-grouping parens (?:...). This also avoids the need for
parens around the whole format:
> p = Pattern(r'abc(?:(?!abc).)+jk')
> print p.findall(s)
> ['abc789jk']
>
> Denis
This one works! Thank you Denis. I'll try it out on the actual much longer
(m
Andre Engels gmail.com> writes:
>
> 2009/4/28 Marek Spociński go2.pl,Poland 10g.pl>:
> > I suggest using r'abc.+?jk' instead.
> >
>
> That was my first idea too, but it does not work for this case,
> because Python will still try to _start_ the match as soon as
> possible.
yeah, i tried t
Le Tue, 28 Apr 2009 11:06:16 +0200,
Marek spociń...@go2.pl, Poland s'exprima ainsi:
> > Hello,
> >
> > The following code returns 'abc123abc45abc789jk'. How do I revise the
> > pattern so that the return value will be 'abc789jk'? In other words, I
> > want to find the pattern 'abc' that is clos
Dnia 28 kwietnia 2009 11:16 Andre Engels napisał(a):
> 2009/4/28 Marek spociń...@go2.pl,Poland :
> >> Hello,
> >>
> >> The following code returns 'abc123abc45abc789jk'. How do I revise the
> >> pattern so
> >> that the return value will be 'abc789jk'? In other words, I want to find
> >> the
> >>
2009/4/28 Marek spociń...@go2.pl,Poland :
>> Hello,
>>
>> The following code returns 'abc123abc45abc789jk'. How do I revise the
>> pattern so
>> that the return value will be 'abc789jk'? In other words, I want to find the
>> pattern 'abc' that is closest to 'jk'. Here the string '123', '45' and '7
> Hello,
>
> The following code returns 'abc123abc45abc789jk'. How do I revise the pattern
> so
> that the return value will be 'abc789jk'? In other words, I want to find the
> pattern 'abc' that is closest to 'jk'. Here the string '123', '45' and '789'
> are
> just examples. They are actually q
> I wonder if anyone can help me with an RE. I also wonder if there is an
> RE mailing list anywhere - I haven't managed to find one.
Hi Debbie,
I haven't found one either. There appear to be a lot of good resources
here:
http://dmoz.org/Computers/Programming/Languages/Regular_Expressions
D Elliott wrote:
I wonder if anyone can help me with an RE. I also wonder if there is an
RE mailing list anywhere - I haven't managed to find one.
I'm trying to use this regular expression to delete particular strings
from a file before tokenising it.
I want to delete all strings that have a fu
Mike Hall wrote:
A simple example will show what I mean:
>>> import re
>>> x = re.compile(r"(A) | (B)")
>>> s = "X R A Y B E"
>>> r = x.sub("13", s)
>>> print r
X R 13Y13 E
...so unless I'm understanding it wrong, "B" is supposed to be ignored
if "A" is matched, yet I get both matched. I get
but yeah, it
seems you're expecting it to examine the string as a whole.
I guess I was, good point.
On Mar 9, 2005, at 12:28 PM, Liam Clarke wrote:
Actually, you should get that anyway...
"""
|
Alternation, or the ``or'' operator. If A and B are regular
expressions, A|B will match any string t
Oops
I mean
for i in range(len(k)):
i f k[i] == 'A' or k[i]=='B':
k[i ]= 13
On Thu, 10 Mar 2005 09:28:59 +1300, Liam Clarke <[EMAIL PROTECTED]> wrote:
> Actually, you should get that anyway...
>
> """
> |
> Alternation, or the ``or'' operator. If A and B are regular
> express
Actually, you should get that anyway...
"""
|
Alternation, or the ``or'' operator. If A and B are regular
expressions, A|B will match any string that matches either "A" or "B".
| has very low precedence in order to make it work reasonably when
you're alternating multi-character strings. Crow|S
But I only want to ignore "B" if "A" is a match. If "A" is not a match,
I'd like it to advance on to "B".
On Mar 9, 2005, at 12:07 PM, Marcos Mendonça wrote:
Hi
Not and regexp expert. But it seems to me that if you want to ignora
"B" then it should be
(A) | (^B)
Hope it helps!
On Wed, 9 Mar 2005
Indeed I do:
>>> import re
>>> x = re.compile('A|B')
>>> s = " Q A R B C"
>>> r = x.sub("13", s)
>>> print r
Q 13 R 13 C
On Mar 9, 2005, at 12:09 PM, Liam Clarke wrote:
Hi Mike,
Do you get the same results for a search pattern of 'A|B'?
On Wed, 9 Mar 2005 11:11:57 -0800, Mike Hall
<[EMAIL PROTECT
Hi Mike,
Do you get the same results for a search pattern of 'A|B'?
On Wed, 9 Mar 2005 11:11:57 -0800, Mike Hall
<[EMAIL PROTECTED]> wrote:
> I'm having some strange results using the "or" operator. In every test
> I do I'm matching both sides of the "|" metacharacter, not one or the
> other a
I'm having some strange results using the "or" operator. In every test
I do I'm matching both sides of the "|" metacharacter, not one or the
other as all documentation says it should be (the parser supposedly
scans left to right, using the first match it finds and ignoring the
rest). It should
Sorry, my last reply crossed this one (and yes, I forgot again to CC
the list).
I'm experimenting now with your use of the "or" operator( "|") between
two expressions, thanks.
On Mar 8, 2005, at 6:42 PM, Danny Yoo wrote:
On Tue, 8 Mar 2005, Mike Hall wrote:
Yes, my existing regex is using a lo
>
> Regular expressions are a little evil at times; here's what I think you're
> thinking of:
>
> ###
> >>> import re
> >>> pattern = re.compile(r"""dog(?!cat)
> ...| (?<=dogcat)""", re.VERBOSE)
> >>> pattern.match('dogman').start()
> 0
> >>> pattern.search('dogcatcher').start
This will match the position in front of "dog":
(?<=dog)
This will match the position in front of "cat":
(?<=cat)
This will not match in front of "dog" if "dog" is followed by "cat":
(?<=dog)\b (?!cat)
Now my question is how to get this:
(?<=cat)
...but ONLY if "cat" is following "dog." If "dog" do
On Tue, 8 Mar 2005, Mike Hall wrote:
> Yes, my existing regex is using a look behind assertion:
>
> (?<=dog)
>
> ...it's also checking the existence of "Cat":
>
> (?!Cat)
>
> ...what I'm stuck on is how to essentially use a lookbehind on "Cat",
> but only if it exists.
Hi Mike,
[Note: Please
Mike Hall wrote:
First, thanks for the response. Using your re:
my_re = re.compile(r'(dog)(cat)?')
...I seem to simply be matching the pattern "Dog". Example:
>>> str1 = "The dog chased the car"
>>> str2 = "The dog cat parade was under way"
>>> x1 = re.compile(r'(dog)(cat)?')
>>> rep1 = x1.su
First, thanks for the response. Using your re:
my_re = re.compile(r'(dog)(cat)?')
...I seem to simply be matching the pattern "Dog". Example:
>>> str1 = "The dog chased the car"
>>> str2 = "The dog cat parade was under way"
>>> x1 = re.compile(r'(dog)(cat)?')
>>> rep1 = x1.sub("REPLACE", str1)
>>>
On Tue, 8 Mar 2005, Mike Hall wrote:
> I'd like to get a match for a position in a string preceded by a
> specified word (let's call it "Dog"), unless that spot in the string
> (after "Dog") is directly followed by a specific word(let's say "Cat"),
> in which case I want my match to occur direct
Mike Hall wrote:
I'd like to get a match for a position in a string preceded by a
specified word (let's call it "Dog"), unless that spot in the string
(after "Dog") is directly followed by a specific word(let's say "Cat"),
in which case I want my match to occur directly after "Cat", and not "Dog
26 matches
Mail list logo