Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!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.007 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'python,': 0.02; 'tutorial': 0.03; '"this': 0.03; 'yet.': 0.04; 'expressions': 0.07; 'subject:How': 0.10; 'cc:addr:python-list': 0.11; 'python': 0.11; 'example?': 0.16; 'finds': 0.16; 'simplified': 0.16; 'splits': 0.16; 'url:re': 0.16; 'followed': 0.16; 'thanks,': 0.17; 'wrote:': 0.18; 'first.': 0.19; 'thu,': 0.19; 'example': 0.22; 'import': 0.22; 'cc:addr:python.org': 0.22; 'url:moin': 0.24; 'looks': 0.24; 'cc:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; "doesn't": 0.30; 'characters': 0.30; 'message- id:@mail.gmail.com': 0.30; "i'm": 0.30; 'url:mailman': 0.30; 'url:wiki': 0.31; 'quotes': 0.31; 'regular': 0.32; 'quite': 0.32; 'open': 0.33; 'url:python': 0.33; 'subject:the': 0.34; 'could': 0.34; 'but': 0.35; 'received:google.com': 0.35; 'url:listinfo': 0.36; 'hi,': 0.36; 'url:org': 0.36; 'two': 0.37; 'url:library': 0.38; 'anything': 0.39; 'quote': 0.39; 'either': 0.39; 'url:mail': 0.40; 'read': 0.60; 'new': 0.61; 'simple': 0.61; 'first': 0.61; 'here:': 0.62; 'more': 0.64; 'to:addr:gmail.com': 0.65; 'side': 0.67; 'close': 0.67; 'link:': 0.72; 'jul': 0.74; 'start.': 0.84; 'broadcasting': 0.91; 'joel': 0.91; 'sheet': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=fmn0nT2GKFinFQhfa8SndBuwv9cUcDdY/EoowRN2pU0=; b=uLgQwPFqOLKyEHISTvaQR0GnA9AKutavnY7KW260h22rViJFDirkpP0SzlRGAs+TRu JJJGTrIKdCCtWDOhYcZjUPTE2ekCJ1z1MA33hfw5TSn6BJA6ZeT6fKADbVWBTSCMnpKS VWhl1r+tm7j7NRE2TObXOefWyhpvPZIwIwAwW1kw9ONBn8LKm7yUkbzWLS7K0ccnWLMo +S0q5lXnRjYR/7f1HHb9SdmXp9iA6rczgjJN4paXvVpNZi1omszLShCIZOnb1z5CBAD2 +niYJ5JIljWN7VTTgX2tAAODKBFLsR39Dj6MCQlYfnaAAaroPFE0kxNB/x1I4UQ/Ht30 eldQ== MIME-Version: 1.0 X-Received: by 10.52.252.4 with SMTP id zo4mr39211145vdc.20.1405011950028; Thu, 10 Jul 2014 10:05:50 -0700 (PDT) In-Reply-To: <981c1f5f-2c19-4efc-8397-796bde07f39b@googlegroups.com> References: <981c1f5f-2c19-4efc-8397-796bde07f39b@googlegroups.com> Date: Thu, 10 Jul 2014 13:05:49 -0400 Subject: Re: How to decipher :re.split(r"(\(\([^)]+\)\))" in the example From: Joel Goldstick To: fl Content-Type: text/plain; charset=UTF-8 Cc: "python-list@python.org" 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: 55 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1405011952 news.xs4all.nl 2886 [2001:888:2000:d::a6]:35519 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:74320 On Thu, Jul 10, 2014 at 11:37 AM, fl wrote: > Hi, > > This example is from the link: > > https://wiki.python.org/moin/RegularExpression > > > I have thought about it quite a while without a clue yet. I notice that it uses > double quote ", in contrast to ' which I see more often until now. Double quotes or single quotes -- doesn't matter. > It looks very complicated to me. Could you simplified it to a simple example? > You might read up first here: https://docs.python.org/2/library/re.html If you are just new to learning python, regular expressions are not a good place to start. But if you insist, the page you are looking at is more of a cheat sheet . Try the python docs, and tutorial first. Or google. > > Thanks, > > > > > > import re > split_up = re.split(r"(\(\([^)]+\)\))", > "This is a ((test)) of the ((emergency broadcasting station.))") > > The outer parens are for grouping. I'm not good at regexes but it looks like it wants two open parens followed by any number of characters that are anything but a close paren, followed by two close parens. So whenever it finds that pattern it splits off what is on either side of it. > ...which produces: > > > ["This is a ", "((test))", " of the ", "((emergency broadcasting station.))" ] > -- > https://mail.python.org/mailman/listinfo/python-list -- Joel Goldstick http://joelgoldstick.com