Re: Regular expression to structure HTML

2009-10-03 Thread 504cr...@gmail.com
On Oct 2, 11:14 pm, greg wrote: > Brian D wrote: > > This isn't merely a question of knowing when to use the right > > tool. It's a question about how to become a better developer using > > regular expressions. > > It could be said that if you want to learn how to use a > hammer, it's better to pr

Re: Regular expression to structure HTML

2009-10-02 Thread 504cr...@gmail.com
like to turn that re.compile pattern into a MULTILINE expression, combining the re.M and re.X flags? Documentation says that one should be able to use the bitwise OR operator (e.g., re.M | re.X), but I sure couldn't get it to work. Sometimes a hammer actually is the right tool if you hit th

Regular expression to structure HTML

2009-10-01 Thread 504cr...@gmail.com
I'm kind of new to regular expressions, and I've spent hours trying to finesse a regular expression to build a substitution. What I'd like to do is extract data elements from HTML and structure them so that they can more readily be imported into a database. No -- sorry -- I don't want to use Beau

Re: How to insert string in each match using RegEx iterator

2009-06-11 Thread 504cr...@gmail.com
On Jun 10, 10:13 am, Peter Otten <__pete...@web.de> wrote: > 504cr...@gmail.com wrote: > > I wonder if you (or anyone else) might attempt a different explanation > > for the use of the special sequence '\1' in the RegEx syntax. > > > The Python documentation

Re: How to escape # hash character in regex match strings

2009-06-11 Thread 504cr...@gmail.com
On Jun 11, 2:01 am, Lie Ryan wrote: > 504cr...@gmail.com wrote: > > I've encountered a problem with my RegEx learning curve -- how to > > escape hash characters # in strings being matched, e.g.: > > >>>> string = re.escape('123#abc456') > >

How to escape # hash character in regex match strings

2009-06-10 Thread 504cr...@gmail.com
I've encountered a problem with my RegEx learning curve -- how to escape hash characters # in strings being matched, e.g.: >>> string = re.escape('123#abc456') >>> match = re.match('\d+', string) >>> print match <_sre.SRE_Match object at 0x00A6A800> >>> print match.group() 123 The correct resul

Re: How to insert string in each match using RegEx iterator

2009-06-10 Thread 504cr...@gmail.com
On Jun 10, 5:17 am, Paul McGuire wrote: > On Jun 9, 11:13 pm, "504cr...@gmail.com" <504cr...@gmail.com> wrote: > > > By what method would a string be inserted at each instance of a RegEx > > match? > > Some might say that using a parsing library for this pr

Re: How to insert string in each match using RegEx iterator

2009-06-09 Thread 504cr...@gmail.com
On Jun 9, 11:35 pm, "504cr...@gmail.com" <504cr...@gmail.com> wrote: > On Jun 9, 11:19 pm, Roy Smith wrote: > > > > > In article > > , > > >  "504cr...@gmail.com" <504cr...@gmail.com> wrote: > > > By what method would

Re: How to insert string in each match using RegEx iterator

2009-06-09 Thread 504cr...@gmail.com
On Jun 9, 11:19 pm, Roy Smith wrote: > In article > , > >  "504cr...@gmail.com" <504cr...@gmail.com> wrote: > > By what method would a string be inserted at each instance of a RegEx > > match? > > > For example: > > > string = '123 a

How to insert string in each match using RegEx iterator

2009-06-09 Thread 504cr...@gmail.com
By what method would a string be inserted at each instance of a RegEx match? For example: string = '123 abc 456 def 789 ghi' newstring = ' INSERT 123 abc INSERT 456 def INSERT 789 ghi' Here's the code I started with: >>> rePatt = re.compile('\d+\s') >>> iterator = rePatt.finditer(string) >>> co