Re: Pattern-match & Replace - help required

2012-12-19 Thread MRAB
On 2012-12-19 14:11, Alexander Blinne wrote: Am 19.12.2012 14:41, schrieb AT: Thanks a million Can you recommend a good online book/tutorial on regular expr. in python? http://docs.python.org/3/howto/regex.html Another good resource is: http://www.regular-expressions.info/ -- http://mail.p

Re: Pattern-match & Replace - help required

2012-12-19 Thread Alexander Blinne
Am 19.12.2012 14:41, schrieb AT: > Thanks a million > Can you recommend a good online book/tutorial on regular expr. in python? http://docs.python.org/3/howto/regex.html -- http://mail.python.org/mailman/listinfo/python-list

Re: Pattern-match & Replace - help required

2012-12-19 Thread AT
On Wednesday, 19 December 2012 18:16:18 UTC+5, Peter Otten wrote: > AT wrote: > > > > > I am new to python and web2py framework. Need urgent help to match a > > > pattern in an string and replace the matched text. > > > > > > I've this string (basically an sql statement): > > > stmnt = 'SE

Re: Pattern-match & Replace - help required

2012-12-19 Thread Peter Otten
AT wrote: > I am new to python and web2py framework. Need urgent help to match a > pattern in an string and replace the matched text. > > I've this string (basically an sql statement): > stmnt = 'SELECT taxpayer.id, > taxpayer.enc_name, > taxpayer.age, > taxpayer.occup

Re: Pattern-match & Replace - help required

2012-12-19 Thread AT
On Wednesday, 19 December 2012 16:27:19 UTC+5, Thomas Bach wrote: > On Wed, Dec 19, 2012 at 02:42:26AM -0800, AT wrote: > > > Hi, > > > > > > I am new to python and web2py framework. Need urgent help to match a > > > pattern in an string and replace the matched text. > > > > > > > Well,

Re: Pattern-match & Replace - help required

2012-12-19 Thread Thomas Bach
On Wed, Dec 19, 2012 at 02:42:26AM -0800, AT wrote: > Hi, > > I am new to python and web2py framework. Need urgent help to match a > pattern in an string and replace the matched text. > Well, what about str.replace then? >>> 'egg, ham, tomato'.replace('ham', 'spam, ham, spam') 'egg, spam, ham,

Re: Pattern-match & Replace - help required

2012-12-19 Thread Steven D'Aprano
On Wed, 19 Dec 2012 03:01:32 -0800, AT wrote: > I just wanted to change taxpayer.enc_name in stmnt to > decrypt(taxpayer.enc_name) > > hope it clarifies? Maybe. Does this help? lunch = "Bread, ham, cheese and tomato." # replace ham with spam offset = lunch.find('ham') if offset != -1: lunch

Re: Pattern-match & Replace - help required

2012-12-19 Thread AT
On Wednesday, 19 December 2012 15:51:22 UTC+5, Steven D'Aprano wrote: > On Wed, 19 Dec 2012 02:42:26 -0800, AT wrote: > > > > > Hi, > > > > > > I am new to python and web2py framework. Need urgent help to match a > > > pattern in an string and replace the matched text. > > > > > > I've

Re: Pattern-match & Replace - help required

2012-12-19 Thread Steven D'Aprano
On Wed, 19 Dec 2012 02:42:26 -0800, AT wrote: > Hi, > > I am new to python and web2py framework. Need urgent help to match a > pattern in an string and replace the matched text. > > I've this string (basically an sql statement): > > stmnt = 'SELECT taxpayer.id, > taxpayer.enc_name, >

Pattern-match & Replace - help required

2012-12-19 Thread AT
Hi, I am new to python and web2py framework. Need urgent help to match a pattern in an string and replace the matched text. I've this string (basically an sql statement): stmnt = 'SELECT taxpayer.id, taxpayer.enc_name, taxpayer.age, taxpayer.occupation FROM

Re: pattern match !

2007-07-15 Thread Asun Friere
On Jul 11, 9:29 pm, Helmut Jarausch <[EMAIL PROTECTED]> wrote: > import re > P=re.compile(r'(\w+(?:[-.]\d+)+)-RHEL3-Linux\.RPM') > S="hpsmh-1.1.1.2-0-RHEL3-Linux.RPM" > PO= P.match(S) > if PO : >print PO.group(1) Isn't a regexp overkill here when this will do: head = filename[:filename.index

Re: pattern match !

2007-07-14 Thread Jay Loden
[EMAIL PROTECTED] wrote: >> A slightly more generic match in case your package names turn out to be less >> consistent than given in the test cases: >> >> #!/usr/bin/python >> >> import re >> pattern = re.compile(r'(\w+?-(\d+[\.-])+\d+?)-\D+.*RPM') >> pkgnames = ["hpsmh-1.1.1.2-0-RHEL3-Linux.RPM",

Re: pattern match !

2007-07-11 Thread Jay Loden
Helmut Jarausch wrote: > [EMAIL PROTECTED] wrote: >> Extract the application name with version from an RPM string like >> hpsmh-1.1.1.2-0-RHEL3-Linux.RPM, i require to extract hpsmh-1.1.1.2-0 >> from above string. Sometimes the RPM string may be hpsmh-1.1.1.2-RHEL3- >> Linux.RPM. >> > > Have a tr

Re: pattern match !

2007-07-11 Thread Helmut Jarausch
[EMAIL PROTECTED] wrote: > Extract the application name with version from an RPM string like > hpsmh-1.1.1.2-0-RHEL3-Linux.RPM, i require to extract hpsmh-1.1.1.2-0 > from above string. Sometimes the RPM string may be hpsmh-1.1.1.2-RHEL3- > Linux.RPM. > Have a try with import re P=re.compile(r'(

Re: pattern match !

2007-07-10 Thread Asun Friere
On Jul 11, 1:40 pm, [EMAIL PROTECTED] wrote: > Extract the application name with version from an RPM string like > hpsmh-1.1.1.2-0-RHEL3-Linux.RPM, i require to extract hpsmh-1.1.1.2-0 > from above string. Sometimes the RPM string may be hpsmh-1.1.1.2-RHEL3- > Linux.RPM. Now that list-like splicin

Re: pattern match !

2007-07-10 Thread Steven D'Aprano
On Wed, 11 Jul 2007 03:40:06 +, hari.siri74 wrote: > Extract the application name with version from an RPM string like > hpsmh-1.1.1.2-0-RHEL3-Linux.RPM, i require to extract hpsmh-1.1.1.2-0 > from above string. Sometimes the RPM string may be hpsmh-1.1.1.2-RHEL3- > Linux.RPM. Thank you for s

pattern match !

2007-07-10 Thread hari . siri74
Extract the application name with version from an RPM string like hpsmh-1.1.1.2-0-RHEL3-Linux.RPM, i require to extract hpsmh-1.1.1.2-0 from above string. Sometimes the RPM string may be hpsmh-1.1.1.2-RHEL3- Linux.RPM. -- http://mail.python.org/mailman/listinfo/python-list