Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!news1.tnib.de!feed.news.tnib.de!news.tnib.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.006 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'intermediate': 0.07; 'matches': 0.07; 'suppose': 0.07; 'string': 0.09; 'alter': 0.09; 'expectation': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'jan': 0.12; '"from': 0.16; 'differs': 0.16; 'experiment.': 0.16; 'interpreter,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'subject:Regular': 0.16; 'words.': 0.16; 'wrote:': 0.18; 'slightly': 0.19; 'written': 0.21; 'header:User-Agent:1': 0.23; '(for': 0.26; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply- To:1': 0.27; 'extract': 0.31; 'extend': 0.32; 'regular': 0.32; 'run': 0.32; 'beginning': 0.33; 'third': 0.33; 'editor': 0.35; 'add': 0.35; 'idle': 0.36; 'like,': 0.36; 'should': 0.36; 'to:addr :python-list': 0.38; 'pm,': 0.38; 'expect': 0.39; 'to:addr:python.org': 0.39; 'either': 0.39; 'received:org': 0.40; 'how': 0.40; 'easy': 0.60; 'expression': 0.60; 'received:173': 0.61; 'first': 0.61; 'times': 0.62; 'email addr:gmail.com': 0.63; 'such': 0.63; 'beat': 0.68; 'hints': 0.68; 'ending': 0.78; 'received:fios.verizon.net': 0.84; 'subject:Search': 0.84; '(i)': 0.91; '(ii)': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: Pattern Search Regular Expression Date: Sat, 15 Jun 2013 16:24:15 -0400 References: <51bc3c4d$0$29997$c3e8da3$5496439d@news.astraweb.com> <5200649f-2b2f-4535-8016-a31369e6e348@googlegroups.com> <2f83304f-8b4c-4af5-9fea-ec894a1b6401@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-173-75-251-66.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130509 Thunderbird/17.0.6 In-Reply-To: <2f83304f-8b4c-4af5-9fea-ec894a1b6401@googlegroups.com> 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: 39 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1371327873 news.xs4all.nl 15965 [2001:888:2000:d::a6]:47954 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:48364 On 6/15/2013 12:28 PM, subhabangalore@gmail.com wrote: > Suppose I want a regular expression that matches both "Sent from my iPhone" and "Sent from my iPod". How do I write such an expression--is the problem, > "Sent from my iPod" > "Sent from my iPhone" > > which can be written as, > re.compile("Sent from my (iPhone|iPod)") > > now if I want to slightly to extend it as, > > "Taken from my iPod" > "Taken from my iPhone" > > I am looking how can I use or in the beginning pattern? > > and the third phase if the intermediate phrase, > > "from my" if also differs or changes. > > In a nutshell I want to extract a particular group of phrases, > where, the beginning and end pattern may alter like, > > (i) either from beginning Pattern B1 to end Pattern E1, > (ii) or from beginning Pattern B1 to end Pattern E2, > (iii) or from beginning Pattern B2 to end Pattern E2, The only hints I will add to those given is that you need a) pattern for a word, and b) a way to 'anchor' the pattern to the beginning and ending of the string so it will only match the first and last words. This is a pretty good re practice problem, so go and practice and experiment. Expect to fail 20 times and you should beat your expectation ;-). The interactive interpreter, or Idle with its F5 Run editor window, makes experimenting easy and (for me) fun. -- Terry Jan Reedy