On 2024-10-19 00:15:23 +0200, jak via Python-list wrote:
> Peter J. Holzer ha scritto:
> > As a trivial example, the regular expressions r"\\sout{" and r"\\sout\{"
> > are equivalent (the \ before the { is redundant). Yet
> > re.compile(s).pattern preserves the difference between the two strings.
>
Peter J. Holzer ha scritto:
As a trivial example, the regular expressions r"\\sout{" and r"\\sout\{"
are equivalent (the \ before the { is redundant). Yet
re.compile(s).pattern preserves the difference between the two strings.
Hi,
Allow me to be fussy: r"\\sout{" and r"\\sout\{" are similar bu
On 2024-10-12 08:51:57 -0400, Thomas Passin via Python-list wrote:
> On 10/12/2024 6:59 AM, Peter J. Holzer via Python-list wrote:
> > On 2024-10-11 17:13:07 -0400, AVI GROSS via Python-list wrote:
> > > Is there some utility function out there that can be called to show what
> > > the
> > > regul
tern)
\w+\\sub
-Original Message-
From: Python-list bounces+avi.e.gross=gmail@python.org> On
Behalf Of Gilmeh Serda via Python-list
Sent: Friday, October 11, 2024 10:44 AM
To: python-list@python.org
Subject: Re: Correct syntax for pathological re.search()
On Mon, 7 Oct 2024 08:3
.
-Original Message-
From: Python-list On
Behalf Of Peter J. Holzer via Python-list
Sent: Saturday, October 12, 2024 7:00 AM
To: python-list@python.org
Subject: Re: Correct syntax for pathological re.search()
On 2024-10-11 17:13:07 -0400, AVI GROSS via Python-list wrote:
> Is there some util
On 10/12/2024 6:59 AM, Peter J. Holzer via Python-list wrote:
On 2024-10-11 17:13:07 -0400, AVI GROSS via Python-list wrote:
Is there some utility function out there that can be called to show what the
regular expression you typed in will look like by the time it is ready to be
used?
I assume
On 2024-10-11 17:13:07 -0400, AVI GROSS via Python-list wrote:
> Is there some utility function out there that can be called to show what the
> regular expression you typed in will look like by the time it is ready to be
> used?
I assume that by "ready to be used" you mean the compiled form?
No,
or pathological re.search()
On Mon, 7 Oct 2024 08:35:32 -0500, Michael F. Stemper wrote:
I'm trying to discard lines that include the string "\sout{" (which is
TeX, for those who are curious. I have tried:
if not re.search("\sout{", line): if not re.search("\sout\{
cases, ...
-Original Message-
From: Python-list On
Behalf Of Gilmeh Serda via Python-list
Sent: Friday, October 11, 2024 10:44 AM
To: python-list@python.org
Subject: Re: Correct syntax for pathological re.search()
On Mon, 7 Oct 2024 08:35:32 -0500, Michael F. Stemper wrote:
> I'
Am Tue, Oct 08, 2024 at 04:59:48PM -0400 schrieb Alan Bawden via Python-list:
> Karsten Hilbert writes:
>
>Python 3.11.2 (main, Aug 26 2024, 07:20:54) [GCC 12.2.0] on linux
>Type "help", "copyright", "credits" or "license" for more
> information.
>>>> tex = '\
On 2024-10-08 21:59, Alan Bawden via Python-list wrote:
Karsten Hilbert writes:
Python 3.11.2 (main, Aug 26 2024, 07:20:54) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more
information.
>>> tex = '\sout{'
>>> tex
Karsten Hilbert writes:
Python 3.11.2 (main, Aug 26 2024, 07:20:54) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more
information.
>>> tex = '\sout{'
>>> tex
'\\sout{'
>>>
Am I missing something ?
Am Tue, Oct 08, 2024 at 08:07:04PM +0100 schrieb MRAB via Python-list:
> >unwanted_tex = '\sout{'
> >if unwanted_tex not in line: do_something_with_libreoffice()
> >
> That should be:
>
> unwanted_tex = r'\sout{'
Hm.
Python 3.11.2 (main, Aug 26 2024, 07:20:54) [GCC 12.2.0] on linux
On 2024-10-07 14:35, Michael F. Stemper via Python-list wrote:
I'm trying to discard lines that include the string "\sout{" (which is TeX, for
those who are curious. I have tried:
if not re.search("\sout{", line):
if not re.search("\sout\{", line):
On 2024-10-08 19:30, Karsten Hilbert via Python-list wrote:
Am Mon, Oct 07, 2024 at 08:35:32AM -0500 schrieb Michael F. Stemper via
Python-list:
I'm trying to discard lines that include the string "\sout{" (which is TeX, for
those who are curious. I have tried:
if not r
Am Mon, Oct 07, 2024 at 08:35:32AM -0500 schrieb Michael F. Stemper via
Python-list:
> I'm trying to discard lines that include the string "\sout{" (which is TeX,
> for
> those who are curious. I have tried:
> if not re.search("\sout{", line):
> if no
On 2024-10-07, Stefan Ram wrote:
> "Michael F. Stemper" wrote or quoted:
>>For now, I'll use the "r" in a cargo-cult fashion, until I decide which
>>syntax I prefer. (Is there any reason that one or the other is preferable?)
>
> I'd totally go with the r-style notation!
>
> It's got one bumme
I'm trying to discard lines that include the string "\sout{" (which is TeX, for
those who are curious. I have tried:
if not re.search("\sout{", line):
if not re.search("\sout\{", line):
if not re.search("\\sout{", line):
if not re.search("
r...@zedat.fu-berlin.de (Stefan Ram) writes:
> "Michael F. Stemper" wrote or quoted:
>
> path = r'C:\Windows\example' + '\\'
>
You could even omit the '+'. Then the concatenation is done at parsing time
instead of run time.
--
Pieter van Oostrum
www: http://pieter.vanoostrum.org/
PGP key: [8DA
On 07/10/2024 08.56, Stefan Ram wrote:
"Michael F. Stemper" wrote or quoted:
if not re.search("\\sout\{", line):
So, if you're not down to slap an "r" before your string literals,
you're going to end up doubling down on every backslash.
Ne
Thanks works fine : )
--
https://mail.python.org/mailman/listinfo/python-list
lock(block):
>
> cmd = "get_block_info -l"
> stdout, stderr, exitcode = subprocess_run(cmd)
> #Grab the block from the stdout
> block = re.search('(?<=\(block )[^(]*(?=\))', stdout).group()
> # check the pattern
> matched = re.search(r'(\d+),
On Sun, May 29, 2016 at 10:32 PM, Matt Wheeler wrote:
>
>
> This doesn't seem to exactly match your code below, i.e. your code is
> attempting to construct a tuple from groups 1 through 4. To meet this
> specification I could just `return re.search('(?<=\(block
&g
On 28 May 2016 at 19:12, Ganesh Pal wrote:
> Dear Python friends,
>
> I am on Python 2.7 and Linux . I am trying to extract the address
> "1,5,147456:8192" from the below stdout using re.search
>
> (Pdb) stdout
> 'linux-host-machine-1: Block Address for 1,5,27
;, '1375772672', '8192')
(Pdb) matched.group()
'Block Address for 1,0,1376034816:8192 (block *1,0,1375772672:8192*'
Regards,
Ganesh
On Sun, May 29, 2016 at 11:53 AM, Ganesh Pal wrote:
>
>
>
>> Perhaps:
>> map(int, re.search(search_pa
> Perhaps:
> map(int, re.search(search_pat, stdout).groups())
>
>
>
Thanks Albert map saved me many lines of code but map returns a list I
will have to convert the list to string again
Below is how Iam planning to teh conversion
>>> block = map(int, re.search(se
> Date: Sat, 28 May 2016 23:48:16 +0530
> Subject: re.search - Pattern matching review ( Apologies re sending)
> From: ganesh1...@gmail.com
> To: python-list@python.org
>
> Dear Python friends,
>
> I am on Python 2.7 and Linux . I am trying to extract the address
>
Dear Python friends,
I am on Python 2.7 and Linux . I am trying to extract the address
"1,5,147456:8192" from the below stdout using re.search
(Pdb) stdout
'linux-host-machine-1: Block Address for 1,5,27320320:8192 (block
1,5,147456:8192) --\nlinux-host-machine-1: m
Dear Python friends,
I am on Python 2.7 and Linux . I am trying to extract the address
"1,5,147456:8192" from the below stdout using re.search
(Pdb) stdout
'linux-host-machine-1: Block Address for 1,5,27320320:8192 (block
1,5,147456:8192) --\nlinux-host-machine-1: m
prev 0 , now 1] -> match any single character from the set "prev0,now1 "
\[prev 0 , now 1\] -> match the actual text [prev 0 , now 1]
Try these:
re.search('[prev 0 , now 1]','p') # matches (p in "prev0,now1 ")
re.search('[prev 0 , now 1]&#x
to be very trivial question but iam breaking my head
> over
> > it for a while .
> >
> > My understanding is that re.search should search for the match anywhere
> in
> > the string .
> >
> >
> > why is re.search failing in the below case ??
> >
Jussi Piitulainen writes:
> Ganesh Pal writes:
>
> > why is re.search failing in the below case ??
>
> Your pattern, '... level-based: [prev 0 , now 1]', matches a literal
> string '--- level-based: ' followed by 'p', 'r', 'e
On Mon, Dec 8, 2014 at 12:52 AM, Ganesh Pal wrote:
> Hi Folks ,
>
> This might seem to be very trivial question but iam breaking my head over
> it for a while .
>
> My understanding is that re.search should search for the match anywhere in
> the string .
>
>
> w
On Dec 08 at 12:22 +0530, Ganesh Pal wrote:
> Hi Folks ,
>
> This might seem to be very trivial question but iam breaking my head over
> it for a while .
>
> My understanding is that re.search should search for the match anywhere in
> the string .
>
>
> why is re.se
Ganesh Pal writes:
> why is re.search failing in the below case ??
Your pattern, '... level-based: [prev 0 , now 1]', matches a literal
string '--- level-based: ' followed by 'p', 'r', 'e', 'v', ' ', '0',
...,
Hi Folks ,
This might seem to be very trivial question but iam breaking my head over
it for a while .
My understanding is that re.search should search for the match anywhere in
the string .
why is re.search failing in the below case ??
>>> pattern
'Token-based migrations c
On Mon, 07 Jan 2013 01:45:58 -0800, iMath wrote:
> 在 2012年9月26日星期三UTC+8下午3时38分50秒,iMath写道:
>> I only know the dollar sign ($) will match a pattern from the
>>
>> end of a string,but which method does it work with ,re.match() or
>> re.search() ?
>
> I thoug
在 2012年9月26日星期三UTC+8下午3时38分50秒,iMath写道:
> I only know the dollar sign ($) will match a pattern from the
>
> end of a string,but which method does it work with ,re.match() or re.search()
> ?
I thought re.match('h.$', 'hbxihi') will match ‘hi’ ,bu
Dennis Lee Bieber wrote:
>
> Unless there has been a major change in the parser... (I still don't
> have Python 3.x installed)
>
> I believe is expanded to 8-spaces -- NOT TO NEXT MULTIPLE OF
> 8...
A tab is *one* character. Your *editor* may show tabs visually
"expanded" or conver
Ramit Prasad wrote:
>
> Dennis Lee Bieber wrote:
> >
> > Unless there has been a major change in the parser... (I still don't
> > have Python 3.x installed)
> >
> > I believe is expanded to 8-spaces -- NOT TO NEXT MULTIPLE OF
> > 8...
>
> A tab is *one* character. Your *editor* may show
Dennis Lee Bieber wrote:
> Unless there has been a major change in the parser... (I still don't
> have Python 3.x installed)
>
> I believe is expanded to 8-spaces -- NOT TO NEXT MULTIPLE OF
> 8...
>
Certainly in Python 2.7 that's not the case: the tab expands to the next
multiple o
On Wed, Nov 28, 2012 at 5:20 PM, Dennis Lee Bieber wrote:
> On 28 Nov 2012 21:39:03 GMT, Steven D'Aprano
> declaimed the following in
> gmane.comp.python.general:> py> if True:
> > ... if True: # tab
> > ... pass # tab, then four spaces
> > ... pass # two spaces, tab, four s
On Thu, Nov 29, 2012 at 8:39 AM, Steven D'Aprano
wrote:
> Perhaps it would be nice if Python honoured a directive setting indent
> style to spaces or indents, as it honours source code encoding lines:
>
> # -*- indent: -*-
>
> Where could be one of:
>
> space[s]Only accept spaces in inde
On Wed, 28 Nov 2012 14:08:15 -0600, Evan Driscoll wrote:
> I'm only entering this thread now so I'm not really in context, but
> you're correct; in Python 3, -tt is set by default, which makes illegal
> mixing an error.
>
> However, not all mixing is illegal: what it means by "code that
> illegal
On Wed, 28 Nov 2012 11:39:48 -0800, Kevin T wrote:
> with other languages i always expand tabs to spaces. the vi plugin does
> do this properly. if i change all indents to be spaces only will python
> behave? i inherited a good deal of the code that i am using, which is
> tab based.
Python wil
On 11/28/2012 01:57 PM, Ian Kelly wrote:
> Yes, it's best to use either tabs-only or spaces-only. Quoting from PEP
> 8 on the subject:
>
> Never mix tabs and spaces.
>
> The most popular way of indenting Python is with spaces only. The
> second-most popular way is with tabs only. Cod
On Wed, Nov 28, 2012 at 12:39 PM, Kevin T wrote:
> with other languages i always expand tabs to spaces. the vi plugin does
do this properly. if i change all indents to be spaces only will python
behave? i inherited a good deal of the code that i am using, which is tab
based.
Yes, it's best to
I agree. Being relatively new to python, i was not sure of quirks so i posted
the original code.
I did find the real issue, as I found another loop that was not being executed
properly.
It turns out that if the indent started with spaces and ended with tabs,
neither eclipse or command line e
On Thu, Nov 22, 2012 at 3:41 AM, Kevin T wrote:
> I went back and tried version a again, blam it is/does work now ?!?!?
> I am not sure what changed but version a was the original code that
> wouldn't work. All the examples i had read, showed version a as a
> working version. I spent significant
On Nov 20, 1:37 pm, Ian Kelly wrote:
> On Tue, Nov 20, 2012 at 12:09 PM, Kevin T wrote:
> > #if re.search( "rsrvd", sigName ) : #version a
> > #if re.search( "rsrvd", sigName ) == None : #version b
> > if re.search( "rsrvd", sig
On Tue, Nov 20, 2012 at 12:37 PM, Ian Kelly wrote:
> On Tue, Nov 20, 2012 at 12:09 PM, Kevin T wrote:
>> #if re.search( "rsrvd", sigName ) : #version a
>> #if re.search( "rsrvd", sigName ) == None : #version b
>> if re.search( "rsrvd", si
On Tue, Nov 20, 2012 at 12:09 PM, Kevin T wrote:
> #if re.search( "rsrvd", sigName ) : #version a
> #if re.search( "rsrvd", sigName ) == None : #version b
> if re.search( "rsrvd", sigName ) is None : #version bb
>print sigName
>n
nt taken
i will change ==/!= to is/is not as most people pointed out.
there is no else because it doesn't work.
i used eclipse in debug mode and a command line execution of the code, both
behave the same way
#if re.search( "rsrvd", sigName ) : #version a
#if re.search( "rs
sigName = signal['functionName'] 352
> if re.search( "rsrvd", sigName ) == None : 353
> print sigName 354 newVal = "%s%s" % (
> '1'*signal['bits'] , ne
On Tue, 20 Nov 2012 01:24:54 +, Steven D'Aprano wrote:
> Your code is mangled to the point of unreadability.
Ah, never mind, that's *my* fault, not yours. Or rather, my news reader
software. Sorry about the noise.
The rest of my post still stands:
- simplify your example to the simplest e
ctionName']
352 if re.search( "rsrvd", sigName ) == None :
353 print sigName
354 newVal = "%s%s" % ( '1'*signal['bits'] , newVal )
#prepend 0's
355 if re.search( "
python version 2.4.3, yes i know that it is old. getting the sysadmin to
update the OS requires a first born.
with the following code..
for signal in register['signals'] :
351 sigName = signal['functionName']
352
On Fri, Sep 28, 2012 at 12:07 PM, Prasad, Ramit
wrote:
> I guess you can consider re.match's pattern to be
> prefixed with '^'.
You can in this case, but they're not equivalent in multi-line mode:
>>> re.match('^two', 'one\ntwo', re.M)
iMath wrote:
> Sent: Wednesday, September 26, 2012 2:39 AM
> To: python-list@python.org
> Subject: regular expression : the dollar sign ($) work with re.match() or
> re.search() ?
>
> I only know the dollar sign ($) will match a pattern from the
> end of a string,but whic
Alister writes:
> On Wed, 26 Sep 2012 10:48:00 +0300, Jussi Piitulainen wrote:
>
> > iMath writes:
> >
> >> I only know the dollar sign ($) will match a pattern from the end
> >> of a string, but which method does it work with, re.match() or
> >>
On Wed, 26 Sep 2012 10:48:00 +0300, Jussi Piitulainen wrote:
> iMath writes:
>
>> I only know the dollar sign ($) will match a pattern from the end of a
>> string, but which method does it work with, re.match() or re.search()
>
> It works with both. With re.match, the
iMath wrote:
> I only know the dollar sign ($) will match a pattern from the
> end of a string,but which method does it work with ,re.match() or
> re.search() ?
Why not try it out in the interactive interpreter? Here's the "deluxe
version":
>>> def demo(patt
On Wed, Sep 26, 2012 at 5:48 PM, Jussi Piitulainen
wrote:
> What was the weird character that you used as a question mark? I
> removed them because they confuse the newsreader I use.
It appears to be Unicode Character 'FULLWIDTH QUESTION MARK' (U+FF1F).
Normally I'd be inclined to simply use U+00
iMath writes:
> I only know the dollar sign ($) will match a pattern from the end of
> a string, but which method does it work with, re.match() or
> re.search()
It works with both. With re.match, the pattern has to match at the
start of the string _and_ the $ has to match the end of t
I only know the dollar sign ($) will match a pattern from the
end of a string,but which method does it work with ,re.match() or re.search() ?
--
http://mail.python.org/mailman/listinfo/python-list
Hey
Thanks.
I just resolved it and yes you are right there was a (hidden) new-line to
it. I found it in a crude way of putting dots before and after. I was to
post about it here and saw your message.
I was not knowing about %r. Thanks for that. Thats a good addition to my
knowledge.
Thanks a bu
Hi Sagar,
In order to be able to help you I propose following:
On 09/15/2011 06:54 AM, Sagar Neve wrote:
. . .
> print "hello..Man_Param=%s,Opt_Param1=%s,
> Opt_Param2=%s\n" %(Man_Param,Opt_Param1,Opt_Param2)
Change above line into
> print "hello..Man_Par
Yes. It is been resolved now for the sample program. however, as mentioned
in other post. It is not working in the main program
On Thu, Sep 15, 2011 at 10:25 AM, Kushal Kumaran <
kushal.kumaran+pyt...@gmail.com> wrote:
> On Thu, Sep 15, 2011 at 10:11 AM, Sagar Neve wrote:
> > Here is the code
>
On Thu, Sep 15, 2011 at 2:55 PM, Kushal Kumaran
wrote:
> That looks like a bash error message. Syntax errors in python show up
> with a stack trace. Run your program using the python interpreter
> like this:
>
> python file.py
> OR
> python3 file.py
>
> whatever is applicable in your environment
On Thu, Sep 15, 2011 at 10:11 AM, Sagar Neve wrote:
> Here is the code
>
>
> url="http://xy.yz.com/us/r1000/012/Purple/b1/c6/e2/mzm.dxkjsfbl..d2.dpkg.ipa";
>
> Man_Param="/us/r1000"
> Opt_Param1="Purple"
> Opt_Param2="dpkg.ipa"
>
> if (Opt_Param2 in url):
> print "hello."
> else:
> print "
;
instead it should qualify.
for key in dictionary:
m=re.search(key, url)
if m !=None:
values=dictionary[key]
for v in values:
v_array=v.split(',')
Man_Param
On Thu, Sep 15, 2011 at 2:41 PM, Sagar Neve wrote:
> ./sample.py: line 9: syntax error near unexpected token `:'
> ./sample.py: line 9: `if (Opt_Param2 in url): '
>
It worked for me in Python 3.2. What version of Python are you using?
ChrisA
--
http://mail.python.org/mailman/listinfo/python-
Here is the code
url="http://xy.yz.com/us/r1000/012/Purple/b1/c6/e2/mzm.dxkjsfbl..d2.dpkg.ipa
"
Man_Param="/us/r1000"
Opt_Param1="Purple"
Opt_Param2="dpkg.ipa"
if (Opt_Param2 in url):
print "hello."
else:
print "bye."
It gives me:
./sample.py: line 9: syntax error near unexpected tok
On Wed, Sep 14, 2011 at 8:33 PM, Sagar Neve wrote:
> If A in B:
> does nt seem to be working.
> Am I missing something here.
Please provide a snippet of the code in question, and be specific
about how it's not working.
Cheers,
Chris
--
http://rebertia.com
--
http://mail.python.org/mailman/listi
If A in B:
does nt seem to be working.
Am I missing something here.
-$agar
On Sep 15, 2011 7:25 AM, "Chris Rebert" wrote:
> On Wed, Sep 14, 2011 at 6:41 PM, Sagar Neve wrote:
>> Hi,
>> I have a small program where I want to do just a small regex operation.
>> I want to see if value of a variable
On Wed, Sep 14, 2011 at 6:41 PM, Sagar Neve wrote:
> Hi,
> I have a small program where I want to do just a small regex operation.
> I want to see if value of a variable 'A' is present in an another variable
> 'B'. The below code works fine but as soon as the variable 'A' has some
> string includ
it fails.
for example say:
B="dpkg.ipaz
The code works fine when A="dpkg"
however the code does not work when A="dpkg.ipa"
if re.search(A,B):
# do something.
Can somebody please help me ?
--
http://mail.python.org/mailman/listinfo/python-list
it fails.
for example say:
B="dpkg.ipaz
The code works fine when A="dpkg"
however the code does not work when A="dpkg.ipa"
if re.search(A,B):
# do something.
Can somebody please help me ?
--
http://mail.python.org/mailman/listinfo/python-list
On 11/02/2011 04:34, Roland Mueller wrote:
Hello,
On 02/07/2011 06:26 PM, Mauro Caceres wrote:
>>> import re
>>> help(re.findall)
Help on function findall in module re:
findall(pattern, string, flags=0)
Return a list of all non-overlapping matches in the string.
If one or more groups are prese
Hello,
On 02/07/2011 06:26 PM, Mauro Caceres wrote:
>>> import re
>>> help(re.findall)
Help on function findall in module re:
findall(pattern, string, flags=0)
Return a list of all non-overlapping matches in the string.
If one or more groups are present in the pattern, return a
list
>>> import re
>>> help(re.findall)
Help on function findall in module re:
findall(pattern, string, flags=0)
Return a list of all non-overlapping matches in the string.
If one or more groups are present in the pattern, return a
list of groups; this will be a list of tuples if the patte
On Thu, Feb 3, 2011 at 3:32 PM,
mhearne808[insert-at-sign-here]gmail[insert-dot-here]com
wrote:
> Here's a scenario:
>
> import re
> m = re.search('e','fredbarneybettywilma')
>
> Now, here's a stupid question:
> why doesn't m.groups() r
On Thu, Feb 3, 2011 at 12:32 PM,
mhearne808[insert-at-sign-here]gmail[insert-dot-here]com
wrote:
> Here's a scenario:
>
> import re
> m = re.search('e','fredbarneybettywilma')
>
> Now, here's a stupid question:
> why doesn't m.grou
Here's a scenario:
import re
m = re.search('e','fredbarneybettywilma')
Now, here's a stupid question:
why doesn't m.groups() return ('e','e','e').
I'm trying to figure out how to match ALL of the instances of a
pattern in o
In article ,
Phlip wrote:
>
>Thanks all for playing! And as usual I forgot a critical detail:
>
>I'm writing a matcher for a Morelia /viridis/ Scenario step, so the
>matcher must be a single regexp.
Why? (You're apparently the author of Morelia, but I don't really
understand it.)
--
Aahz (a...
On 25/11/2010 19:57, Phlip wrote:
Accepting input from a human is fraught with dangers and edge cases.
Here's a non-regex solution
Thanks all for playing! And as usual I forgot a critical detail:
I'm writing a matcher for a Morelia /viridis/ Scenario step, so the
matcher must be a single re
+), )?
(?:(\w+), and )?(\w+)$', 'whatever a, bbb, and c')
print got # [('a', '', '', '', 'bbb', 'c')]
The trick is to simply paste in a high number of (?:(\w+), )?
segments, assuming that nobody should plug in too
On 25/11/2010 04:46, Phlip wrote:
HypoNt:
I need to turn a human-readable list into a list():
print re.search(r'(?:(\w+), |and (\w+))+', 'whatever a, bbb, and
c').groups()
That currently returns ('c',). I'm trying to match "any word \w+
followed by
On 11/24/2010 10:46 PM, Phlip wrote:
> HypoNt:
>
> I need to turn a human-readable list into a list():
>
>print re.search(r'(?:(\w+), |and (\w+))+', 'whatever a, bbb, and
> c').groups()
>
> That currently returns ('c',). I'm tryi
Phlip,
> I'm trying to match "any word \w+ followed by a comma, or a final word
> preceded by and."
Here's a non-regex solution that handles multi-word values and multiple
instances of 'and' (as pointed out by Alice). The posted code could be
simplified via list comprehension - I chose the more
Now that I think about it, and can be stripped using a callback
function as the 'normalize' argument to my KeywordProcessor class:
def normalize(value):
value = value.strip()
if value.startswith("and"):
value = value[3:]
return value
parser = KeywordProcessor(',', normalize=no
Accepting input from a human is frought with dangers and edge cases. ;)
Some time ago I wrote a regular expression generator that creates
regexen that can parse arbitrarily delimited text, supports quoting (to
avoid accidentally separating two elements that should be treated as
one), and work
--- On Thu, 11/25/10, Phlip wrote:
> From: Phlip
> Subject: a regexp riddle: re.search(r'
> To: python-list@python.org
> Date: Thursday, November 25, 2010, 8:46 AM
> HypoNt:
>
> I need to turn a human-readable list into a list():
>
> print re.search(r'(
HypoNt:
I need to turn a human-readable list into a list():
print re.search(r'(?:(\w+), |and (\w+))+', 'whatever a, bbb, and
c').groups()
That currently returns ('c',). I'm trying to match "any word \w+
followed by a comma, or a final word preceded by
Bruno Desthuilliers wrote:
Pat a écrit :
Bruno Desthuilliers wrote:
Pat a écrit :
While I can use a for loop looking for a match on a list, I was
wondering if there was a one-liner way.
In particular, one of my RE's looks like this '^somestring$' so I
can't jus
Steve Holden a écrit :
Pat wrote:
Bruno Desthuilliers wrote:
(snip)
words = ['foo', 'bar', 'somestring', 'baaz']
re.search(r"^somestring$", "\n".join(words), re.MULTILINE)
(snip)
I suspect that
any(re.match(pat, word)
Pat wrote:
> Bruno Desthuilliers wrote:
>> Pat a écrit :
>>> While I can use a for loop looking for a match on a list, I was
>>> wondering if there was a one-liner way.
>>>
>>> In particular, one of my RE's looks like this '^somestring$'
Pat a écrit :
Bruno Desthuilliers wrote:
Pat a écrit :
While I can use a for loop looking for a match on a list, I was
wondering if there was a one-liner way.
In particular, one of my RE's looks like this '^somestring$' so I
can't just do this: re.search( '^
Bruno Desthuilliers wrote:
Pat a écrit :
While I can use a for loop looking for a match on a list, I was
wondering if there was a one-liner way.
In particular, one of my RE's looks like this '^somestring$' so I
can't just do this: re.search( '^somestring$', s
Pat a écrit :
While I can use a for loop looking for a match on a list, I was
wondering if there was a one-liner way.
In particular, one of my RE's looks like this '^somestring$' so I can't
just do this: re.search( '^somestring$', str( mylist ) )
I'm not
1 - 100 of 189 matches
Mail list logo