Re: pattern matching

2011-02-24 Thread Jon Clements
On Feb 24, 2:11 am, monkeys paw wrote: > if I have a string such as '01/12/2011' and i want > to reformat it as '20110112', how do i pull out the components > of the string and reformat them into a DDMM format? > > I have: > > import re > > test = re.compile('\d\d\/') > f = open('test.html')  

Re: pattern matching

2011-02-24 Thread John S
On Feb 23, 9:11 pm, monkeys paw wrote: > if I have a string such as '01/12/2011' and i want > to reformat it as '20110112', how do i pull out the components > of the string and reformat them into a DDMM format? > > I have: > > import re > > test = re.compile('\d\d\/') > f = open('test.html')  

Re: pattern matching

2011-02-23 Thread Dr Vangel
if I have a string such as '01/12/2011' and i want to reformat it as '20110112', how do i pull out the components of the string and reformat them into a DDMM format? I have: import re test = re.compile('dd/') f = open('test.html') # This file contains the html dates for line in f: if

Re: pattern matching

2011-02-23 Thread Roy Smith
In article , Chris Rebert wrote: > regex = compile("(\d\d)/(\d\d)/(\d{4})") I would probably write that as either r"(\d{2})/(\d{2})/(\d{4})" or (somewhat less likely) r"(\d\d)/(\d\d)/(\d\d\d\d)" Keeping to one consistent style makes it a little easier to read. Also, don't forget the leadi

Re: pattern matching

2011-02-23 Thread Chris Rebert
On Wed, Feb 23, 2011 at 6:37 PM, Steven D'Aprano wrote: > On Wed, 23 Feb 2011 21:11:53 -0500, monkeys paw wrote: >> if I have a string such as '01/12/2011' and i want to reformat >> it as '20110112', how do i pull out the components of the string and >> reformat them into a DDMM format? > > da

Re: pattern matching

2011-02-23 Thread Steven D'Aprano
On Wed, 23 Feb 2011 21:11:53 -0500, monkeys paw wrote: > if I have a string such as '01/12/2011' and i want to reformat > it as '20110112', how do i pull out the components of the string and > reformat them into a DDMM format? data = '01/12/2011' # Throw away tags. data = data[4:-5] # Separat

Re: pattern matching

2011-02-23 Thread Roy Smith
In article , monkeys paw wrote: > if I have a string such as '01/12/2011' and i want > to reformat it as '20110112', how do i pull out the components > of the string and reformat them into a DDMM format? > > I have: > > import re > > test = re.compile('\d\d\/') > f = open('test.html') #

Re: pattern matching with multiple lists

2010-07-16 Thread Tim Chase
On 07/16/2010 02:20 PM, Chad Kellerman wrote: Greetings, I have some code that I wrote and know there is a better way to write it. I wonder if anyone could point me in the right direction on making this 'cleaner'. I have two lists: liveHostList = [ app11, app12, web11, web12, hos

Re: pattern matching with multiple lists

2010-07-16 Thread MRAB
Chad Kellerman wrote: Greetings, I have some code that I wrote and know there is a better way to write it. I wonder if anyone could point me in the right direction on making this 'cleaner'. I have two lists: liveHostList = [ app11, app12, web11, web12, host11 ]

Re: Pattern Matching Over Python Lists

2008-06-22 Thread eliben
> Fair enough. To help you understand the method I used, I'll give you > this hint. It's true that regex on works on strings. However, is there > any way to convert arbitrarily complex data structures to string > representations? You don't need to be an experienced Python user to > answer to this ;

Re: Pattern Matching Over Python Lists

2008-06-22 Thread Chris
On Jun 19, 9:03 pm, John Machin <[EMAIL PROTECTED]> wrote: > On Jun 20, 10:45 am, Chris <[EMAIL PROTECTED]> wrote: > > > On Jun 17, 1:09 pm, [EMAIL PROTECTED] wrote: > > > > Kirk Strauser: > > > > > Hint: recursion. Your general algorithm will be something like: > > > > Another solution is to use

Re: Pattern Matching Over Python Lists

2008-06-20 Thread MRAB
On Jun 20, 1:45 am, Chris <[EMAIL PROTECTED]> wrote: > On Jun 17, 1:09 pm, [EMAIL PROTECTED] wrote: > > > Kirk Strauser: > > > > Hint: recursion.  Your general algorithm will be something like: > > > Another solution is to use a better (different) language, that has > > built-in pattern matching, o

Re: Pattern Matching Over Python Lists

2008-06-19 Thread Paddy
On Jun 20, 1:44 am, Chris <[EMAIL PROTECTED]> wrote: > Thanks for your help. Those weren't quite what I was looking for, but > I ended up figuring it out on my own. Turns out you can actually > search nested Python lists using simple regular expressions. Strange? How do you match nested '[' ... ']

Re: Pattern Matching Over Python Lists

2008-06-19 Thread John Machin
On Jun 20, 10:45 am, Chris <[EMAIL PROTECTED]> wrote: > On Jun 17, 1:09 pm, [EMAIL PROTECTED] wrote: > > > Kirk Strauser: > > > > Hint: recursion. Your general algorithm will be something like: > > > Another solution is to use a better (different) language, that has > > built-in pattern matching,

Re: Pattern Matching Over Python Lists

2008-06-19 Thread Chris
On Jun 17, 1:09 pm, [EMAIL PROTECTED] wrote: > Kirk Strauser: > > > Hint: recursion. Your general algorithm will be something like: > > Another solution is to use a better (different) language, that has > built-in pattern matching, or allows to create one. > > Bye, > bearophile Btw, Python's stdl

Re: Pattern Matching Over Python Lists

2008-06-19 Thread Chris
Thanks for your help. Those weren't quite what I was looking for, but I ended up figuring it out on my own. Turns out you can actually search nested Python lists using simple regular expressions. -- http://mail.python.org/mailman/listinfo/python-list

Re: Pattern Matching Over Python Lists

2008-06-17 Thread bearophileHUGS
Kirk Strauser: > Hint: recursion. Your general algorithm will be something like: Another solution is to use a better (different) language, that has built-in pattern matching, or allows to create one. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: Pattern Matching Over Python Lists

2008-06-17 Thread Kirk Strauser
At 2008-06-17T05:55:52Z, Chris <[EMAIL PROTECTED]> writes: > Is anyone aware of any prior work done with searching or matching a > pattern over nested Python lists? I have this problem where I have a > list like: > > [1, 2, [1, 2, [1, 7], 9, 9], 10] > > and I'd like to search for the pattern [1, 2

Re: Tips Re Pattern Matching / REGEX

2008-03-27 Thread Miki
Hello, > I have a large text file (1GB or so) with structure similar to the > html example below. > > I have to extract content (text between div and tr tags) from this > file and put it into a spreadsheet or a database - given my limited > python knowledge I was going to try to do this with regex

Tips Re Pattern Matching / REGEX

2008-03-27 Thread egonslokar
Hello Python Community, I have a large text file (1GB or so) with structure similar to the html example below. I have to extract content (text between div and tr tags) from this file and put it into a spreadsheet or a database - given my limited python knowledge I was going to try to do this with

Re: pattern matching

2007-03-01 Thread Diez B. Roggisch
azrael wrote: > can someone give me good links for pattern matching in images using > python There is a python-binding available for the OpenCV library, a collection of state-of-the-art CV algorithms. And it comes with a free manual Diez -- http://mail.python.org/mailman/listinfo/python-li

Re: Pattern matching with string and list

2005-12-13 Thread Brett g Porter
BartlebyScrivener wrote: > Even without the marker, can't you do: > > sentence = "the fabric is red" > colors = ["red", "white", "blue"] > > for color in colors: > if (sentence.find(color) > 0): > print color, sentence.find(color) > That depends on whether you're only looking for who

Re: Pattern matching with string and list

2005-12-13 Thread BartlebyScrivener
Even without the marker, can't you do: sentence = "the fabric is red" colors = ["red", "white", "blue"] for color in colors: if (sentence.find(color) > 0): print color, sentence.find(color) -- http://mail.python.org/mailman/listinfo/python-list

Re: Pattern matching with string and list

2005-12-13 Thread BartlebyScrivener
Taking you literally, I'm not sure you need regex. If you know or can find position n, then can't you just: sentence = "the color is $red" patterns = ["blue","red","yellow"] pos = sentence.find("$") for x in patterns: if x==sentence[pos+1:]: print x, pos+1 But maybe I'm oversimplifyin

Re: Pattern matching with string and list

2005-12-12 Thread Tom Anderson
On Mon, 12 Dec 2005 [EMAIL PROTECTED] wrote: > I'd need to perform simple pattern matching within a string using a list > of possible patterns. For example, I want to know if the substring > starting at position n matches any of the string I have a list, as > below: > > sentence = "the color is

Re: Pattern matching with string and list

2005-12-12 Thread Michael Spencer
[EMAIL PROTECTED] wrote: > Hi, > > I'd need to perform simple pattern matching within a string using a > list of possible patterns. For example, I want to know if the substring > starting at position n matches any of the string I have a list, as > below: > > sentence = "the color is $red" > patte

Re: Pattern Matching Given # of Characters and no String Input; use RegularExpressions?

2005-04-22 Thread Synonymous
Hello! I was trying to create a program to search for the largest common subsetstring among filenames in a directory, them move the filenames to the substring's name. I have succeeded, with help, in doing so and here is the code. Thanks for your help! --- Code --- #This program was created wit

Re: Pattern Matching Given # of Characters and no String Input; use RegularExpressions?

2005-04-20 Thread Synonymous
tiissa <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>... > Synonymous wrote: > > tiissa <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>... > > > >>tiissa wrote: > >> > >>>If you know the number of characters to match can't you just compare > >>>slices? > >> > >>If you

Re: Pattern Matching Given # of Characters and no String Input; use RegularExpressions?

2005-04-20 Thread Synonymous
John Machin <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>... > On 17 Apr 2005 18:12:19 -0700, [EMAIL PROTECTED] (Synonymous) > wrote: > > > > >I will look for a Left$(str) function that looks at the first X > >characters for python :)). > > > > Wild goose chase alert! AFAIK there

Re: Pattern Matching Given # of Characters and no String Input; use RegularExpressions?

2005-04-18 Thread tiissa
Synonymous wrote: tiissa <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>... tiissa wrote: If you know the number of characters to match can't you just compare slices? If you don't, you can still do it by hand: In [7]: def cmp(s1,s2): : diff_map=[chr(s1[i]!=s2[i]) for i in r

Re: Pattern Matching Given # of Characters and no String Input; use RegularExpressions?

2005-04-17 Thread John Machin
On 17 Apr 2005 18:12:19 -0700, [EMAIL PROTECTED] (Synonymous) wrote: > >I will look for a Left$(str) function that looks at the first X >characters for python :)). > Wild goose chase alert! AFAIK there isn't one. Python uses slice notation instead of left/mid/right/substr/whatever functions. I do

Re: Pattern Matching Given # of Characters and no String Input; use RegularExpressions?

2005-04-17 Thread Synonymous
tiissa <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>... > tiissa wrote: > > If you know the number of characters to match can't you just compare > > slices? > If you don't, you can still do it by hand: > > In [7]: def cmp(s1,s2): >: diff_map=[chr(s1[i]!=s2[i]) for i in

Re: Pattern Matching Given # of Characters and no String Input; useRegularExpressions?

2005-04-17 Thread Kent Johnson
tiissa wrote: Synonymous wrote: Can regular expressions compare file names to one another. It seems RE can only compare with input i give it, while I want it to compare amongst itself and give me matches if the first x characters are similiar. Do you have to use regular expressions? If you know the

Re: Pattern Matching Given # of Characters and no String Input; use RegularExpressions?

2005-04-17 Thread tiissa
tiissa wrote: If you know the number of characters to match can't you just compare slices? If you don't, you can still do it by hand: In [7]: def cmp(s1,s2): : diff_map=[chr(s1[i]!=s2[i]) for i in range(min(len(s1), len(s2)))] : diff_index=''.join(diff_map).find(chr(True)) .

Re: Pattern Matching Given # of Characters and no String Input; use RegularExpressions?

2005-04-17 Thread tiissa
Synonymous wrote: Can regular expressions compare file names to one another. It seems RE can only compare with input i give it, while I want it to compare amongst itself and give me matches if the first x characters are similiar. Do you have to use regular expressions? If you know the number of cha

Re: Pattern matching from a text document

2005-03-24 Thread F. Petitjean
Le 24 Mar 2005 06:16:12 -0800, Ben a écrit : > > Below is a few sample lines. There is the name followed by the class > (not important) followed by 5 digits each of which can range 1-9 and > each detail a different ability, such as fitness, attacking ability > etc. Finally the preferred foot is st

Re: Pattern matching from a text document

2005-03-24 Thread Ben
George Sakkis wrote: > B > "Ben" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > > I'm currently trying to develop a demonstrator in python for an > > ontology of a football team. At present all the fit players are > > exported to a text document. > > > > The program reads the docu

Re: Pattern matching from a text document

2005-03-24 Thread Larry Bates
Ben, Others have answered your specific questions, but I thought I'd use this opportunity to make a general statement. Unlike other programming languages, Python doesn't make its built-in functions keywords. You should never, ever, ever name a variable 'list' (the same is true of dict, tuple, st

Re: Pattern matching from a text document

2005-03-23 Thread infidel
First, if you're going to loop over each line, do it like this: for line in file('playerlist.txt'): #do stuff here Second, this statement is referencing the *second* item in the list, not the first: match = ph.match(list[1]) Third, a simple splitting of the lines by some delimiter character

Re: Pattern matching from a text document

2005-03-23 Thread George Sakkis
B "Ben" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > I'm currently trying to develop a demonstrator in python for an > ontology of a football team. At present all the fit players are > exported to a text document. > > The program reads the document in and splits each line into a st