Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.015 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'framework.': 0.07; 'subject:help': 0.07; 'python': 0.09; 'matched': 0.09; 'dec': 0.15; 'complicated,': 0.16; 'subject:required': 0.16; 'then?': 0.16; 'wed,': 0.16; 'string': 0.17; 'wrote:': 0.17; '>>>': 0.18; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'replace': 0.27; 'spam,': 0.29; 'to:addr:python-list': 0.33; 'hi,': 0.33; 'text.': 0.35; 'charset:us-ascii': 0.36; 'subject:: ': 0.38; 'received:10': 0.38; 'to:addr:python.org': 0.39; 'subject:-': 0.40; 'help': 0.40; 'content-disposition:inline': 0.60; 'more': 0.63; 'urgent': 0.66; 'subject: & ': 0.67; 'received:10.94': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=uni-mainz.de; i=@uni-mainz.de; q=dns/txt; s=ironport; t=1355916449; x=1387452449; h=date:from:to:subject:message-id:references:mime-version: in-reply-to; bh=ihw0Fx9vLnMp8YC3CdauN/SrcAfdXnC8ONe6qf6pB9M=; b=UwsRbWshVX+K6EW7bsTJglAVA2i8LjZ10lDJ4qAj1GbvScFIj2V71GDi PMp1dQ6kUaFMVxMVAwOBVitOZph2GZ/MCUkLtreZxmRCOCpaXzPfSOUso pjmtb3SqEZMThJ+2SHuFGuMBzYA/cZeFA43L2NKjO3RVi8L9FVgx01Ts0 c=; X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: An8GADWk0VAKXgZY/2dsb2JhbABFg0i6UHOCHgEBBTpPCxgeEBQpIIgquD2MS4EagkhhA5YJAZBIgnWCIQ Date: Wed, 19 Dec 2012 12:27:19 +0100 From: Thomas Bach To: Subject: Re: Pattern-match & Replace - help required References: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-Originating-IP: [88.68.250.225] X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 18 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1355916450 news.xs4all.nl 6923 [2001:888:2000:d::a6]:43677 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:35098 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, spam, tomato' If the pattern you want to match is more complicated, have a look at the re module! Regards, Thomas.