Re: String splitting with exceptions

2013-08-29 Thread wxjmfauth
Le mercredi 28 août 2013 18:44:53 UTC+2, John Levine a écrit : > I have a crufty old DNS provisioning system that I'm rewriting and I > > hope improving in python. (It's based on tinydns if you know what > > that is.) > > > > The record formats are, in the worst case, like this: > > > > fo

Re: String splitting with exceptions

2013-08-28 Thread John Levine
>Can you have brackets within brackets? If so, this is impossible to deal >with within a regex. Nope. It's a regular language, not a CFL. >Otherwise: re.findall('((?:[^[:]|\[[^]]*\])*):?',s) >['foo.[DOM]', '', '[IP6::4361:6368:6574]', '600', '', ''] That seems to do it, thanks. -- Regard

Re: String splitting with exceptions

2013-08-28 Thread Peter Otten
Neil Cerutti wrote: > On 2013-08-28, John Levine wrote: >> I have a crufty old DNS provisioning system that I'm rewriting and I >> hope improving in python. (It's based on tinydns if you know what >> that is.) >> >> The record formats are, in the worst case, like this: >> >> foo.[DOM]::[IP6::436

Re: String splitting with exceptions

2013-08-28 Thread Neil Cerutti
On 2013-08-28, Tim Chase wrote: > On 2013-08-28 13:14, random...@fastmail.us wrote: >> On Wed, Aug 28, 2013, at 12:44, John Levine wrote: >> > I have a crufty old DNS provisioning system that I'm rewriting >> > and I hope improving in python. (It's based on tinydns if you >> > know what that is.)

Re: String splitting with exceptions

2013-08-28 Thread Neil Cerutti
On 2013-08-28, John Levine wrote: > I have a crufty old DNS provisioning system that I'm rewriting and I > hope improving in python. (It's based on tinydns if you know what > that is.) > > The record formats are, in the worst case, like this: > > foo.[DOM]::[IP6::4361:6368:6574]:600:: > > What I

Re: String splitting with exceptions

2013-08-28 Thread Tim Chase
On 2013-08-28 13:14, random...@fastmail.us wrote: > On Wed, Aug 28, 2013, at 12:44, John Levine wrote: > > I have a crufty old DNS provisioning system that I'm rewriting > > and I hope improving in python. (It's based on tinydns if you > > know what that is.) > > > > The record formats are, in th

Re: String splitting with exceptions

2013-08-28 Thread random832
On Wed, Aug 28, 2013, at 12:44, John Levine wrote: > I have a crufty old DNS provisioning system that I'm rewriting and I > hope improving in python. (It's based on tinydns if you know what > that is.) > > The record formats are, in the worst case, like this: > > foo.[DOM]::[IP6::4361:6368:6574]

Re: String splitting with exceptions

2013-08-28 Thread Skip Montanaro
> The record formats are, in the worst case, like this: > > foo.[DOM]::[IP6::4361:6368:6574]:600:: > Any suggestions? Write a little parser that can handle the record format? Skip -- http://mail.python.org/mailman/listinfo/python-list

String splitting with exceptions

2013-08-28 Thread John Levine
I have a crufty old DNS provisioning system that I'm rewriting and I hope improving in python. (It's based on tinydns if you know what that is.) The record formats are, in the worst case, like this: foo.[DOM]::[IP6::4361:6368:6574]:600:: What I would like to do is to split this string into a li

Re: String splitting by spaces question

2011-11-23 Thread DevPlayer
This is an 'example string' Don't for get to watch for things like: Don't, Can't, Won't, I'll, He'll, Hor'davors, Mc'Kinly -- http://mail.python.org/mailman/listinfo/python-list

Re: String splitting by spaces question

2011-11-23 Thread Phil Rist
In article <3f19e4c0-e010-4cb2-9f71-dd09e0d3c...@r9g2000vbw.googlegroups.com>, Massi says... > >Hi everyone, > >I have to parse a string and splitting it by spaces. The problem is >that the string can include substrings comprises by quotations which >must mantain the spaces. What I need is to pass

Re: String splitting by spaces question

2011-11-23 Thread Miki Tebeka
http://docs.python.org/library/shlex.html -- http://mail.python.org/mailman/listinfo/python-list

Re: String splitting by spaces question

2011-11-23 Thread Jerry Hill
On Wed, Nov 23, 2011 at 12:10 PM, Massi wrote: > Hi everyone, > > I have to parse a string and splitting it by spaces. The problem is > that the string can include substrings comprises by quotations which > must mantain the spaces. What I need is to pass from a string like: > > This is an 'exampl

Re: String splitting by spaces question

2011-11-23 Thread Nick Dokos
Alemu Tadesse wrote: > Can we use rsplit function on an array or vector of strings ? it works > for one not for vector > ... > > I have to parse a string and splitting it by spaces. The problem is > that the string can include substrings comprises by quotations which > must mantain the spaces.

Re: String splitting by spaces question

2011-11-23 Thread Arnaud Delobelle
On 23 November 2011 17:10, Massi wrote: > Hi everyone, > > I have to parse a string and splitting it by spaces. The problem is > that the string can include substrings comprises by quotations which > must mantain the spaces. What I need is to pass from a string like: > > This is an 'example string

RE: String splitting by spaces question

2011-11-23 Thread Alemu Tadesse
: Wednesday, November 23, 2011 10:10 AM To: python-list@python.org Subject: String splitting by spaces question Hi everyone, I have to parse a string and splitting it by spaces. The problem is that the string can include substrings comprises by quotations which must mantain the spaces. What I need is to

String splitting by spaces question

2011-11-23 Thread Massi
Hi everyone, I have to parse a string and splitting it by spaces. The problem is that the string can include substrings comprises by quotations which must mantain the spaces. What I need is to pass from a string like: This is an 'example string' to the following vector: ["This", "is", "an", "ex

Re: string splitting

2006-10-17 Thread George Sakkis
[EMAIL PROTECTED] wrote: > Hello, > I have thousands of files that look something like this: > > wisconsin_state.txt > french_guiana_district.txt > central_african_republic_province.txt > > I need to extract the string between the *last* underscore and the > extention. > So based on the files abov

Re: string splitting

2006-10-17 Thread stefaan
> Anyone have any ideas? l = "wisconsin_state.txt" l.split(".")[0].split("_")[-1] Explanation: --- the split(".")[0] part takes everything before the "." the split("_")[-1] part selects in the last element in the list of substrings which are separated by "_" -- http://mail.pyth

Re: string splitting

2006-10-16 Thread bearophileHUGS
A pair of solutions: >>> s = "central_african_republic_province.txt" >>> s.rsplit("_", 1)[-1].split(".")[0] 'province' >>> import re >>> p = re.compile(r"_ ([^_]+) \.", re.VERBOSE) >>> s = """\ ... wisconsin_state.txt ... french_guiana_district.txt ... central_african_republic_province.txt""" >>>

Re: string splitting

2006-10-16 Thread rdharles
Much thanks for your replies hiaips & Simon! R.D. -- http://mail.python.org/mailman/listinfo/python-list

Re: string splitting

2006-10-16 Thread hiaips
[EMAIL PROTECTED] wrote: > Hello, > I have thousands of files that look something like this: > > wisconsin_state.txt > french_guiana_district.txt > central_african_republic_province.txt > > I need to extract the string between the *last* underscore and the > extention. > So based on the files abov

Re: string splitting

2006-10-16 Thread Simon Brunning
On 16 Oct 2006 12:12:38 -0700, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > Hello, > I have thousands of files that look something like this: > > wisconsin_state.txt > french_guiana_district.txt > central_african_republic_province.txt > > I need to extract the string between the *last* underscore

string splitting

2006-10-16 Thread rdharles
Hello, I have thousands of files that look something like this: wisconsin_state.txt french_guiana_district.txt central_african_republic_province.txt I need to extract the string between the *last* underscore and the extention. So based on the files above, I want returned: state district province

Re: Quote-aware string splitting

2005-04-26 Thread Jeffrey Froman
Bengt Richter wrote: > Oops, note some spaces inside quotes near ss and missing double quotes in > result. And here I thought the main problem with my answer was that it didn't split unquoted segments into separate words at all! Clearly I missed the generalization being sought, and a more robust

Re: Quote-aware string splitting

2005-04-26 Thread Paul McGuire
Quoted strings are surprisingly stateful, so that using a parser isn't totally out of line. Here is a pyparsing example with some added test cases. Pyparsing's quotedString built-in handles single or double quotes (if you don't want to be this permissive, there are also sglQuotedString and dblQuo

Re: Quote-aware string splitting

2005-04-26 Thread Bengt Richter
On Mon, 25 Apr 2005 19:40:44 -0700, Jeffrey Froman <[EMAIL PROTECTED]> wrote: >J. W. McCall wrote: > >> For example, given the string: >> >> 'spam "the life of brian" 42' >> >> I'd want it to return: >> >> ['spam', 'the life of brian', '42'] > >The .split() method of strings can take a substrin

Re: Quote-aware string splitting

2005-04-25 Thread George Sakkis
> import re > regex = re.compile(r''' >'.*?' | # single quoted substring >".*?" | # double quoted substring >\S+ # all the rest >''', re.VERBOSE) Oh, and if your strings may span more than one line, replace re.V

Re: Quote-aware string splitting

2005-04-25 Thread Jeffrey Froman
J. W. McCall wrote: > For example, given the string: > > 'spam "the life of brian" 42' > > I'd want it to return: > > ['spam', 'the life of brian', '42'] The .split() method of strings can take a substring, such as a quotation mark, as a delimiter. So a simple solution is: >>> x = 'spam "the

Re: Quote-aware string splitting

2005-04-25 Thread George Sakkis
> "J. W. McCall" <[EMAIL PROTECTED]> writes: > > > > I need to split a string as per string.strip(), but with a > > modification: I want it to recognize quoted strings and return them as > > one list item, regardless of any whitespace within the quoted string. > > > > For example, given the string:

RE: Quote-aware string splitting

2005-04-25 Thread Tony Meyer
> I need to split a string as per string.strip(), but with a > modification: > I want it to recognize quoted strings and return them as one > list item, > regardless of any whitespace within the quoted string. See the recent python-tutor thread starting here:

Re: Quote-aware string splitting

2005-04-25 Thread Tim Heaney
"J. W. McCall" <[EMAIL PROTECTED]> writes: > > I need to split a string as per string.strip(), but with a > modification: I want it to recognize quoted strings and return them as > one list item, regardless of any whitespace within the quoted string. > > For example, given the string: > > 'spam "th

Quote-aware string splitting

2005-04-25 Thread J. W. McCall
Hello, I need to split a string as per string.strip(), but with a modification: I want it to recognize quoted strings and return them as one list item, regardless of any whitespace within the quoted string. For example, given the string: 'spam "the life of brian" 42' I'd want it to return: ['spa