Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!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.047 X-Spam-Evidence: '*H*': 0.91; '*S*': 0.00; 'be:': 0.09; 'method:': 0.09; 'url:github': 0.09; "'_')": 0.16; 'subject:search': 0.16; 'wrote:': 0.17; 'import': 0.21; "i'd": 0.22; 'to:2**1': 0.23; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'subject:/': 0.28; 'skip:( 20': 0.28; "skip:' 10": 0.30; 'function': 0.30; 'seconds': 0.30; 'print': 0.32; 'to:addr:python- list': 0.33; 'received:google.com': 0.34; 'compared': 0.35; 'pm,': 0.35; 'received:209.85': 0.35; 'message-id:@gmail.com': 0.36; 'method': 0.36; 'charset:us-ascii': 0.36; 'skip:p 20': 0.36; 'received:209': 0.37; 'subject:: ': 0.38; 'received:10': 0.38; 'to:addr:python.org': 0.39; 'skip:a 40': 0.61; 'of:': 0.65; 'url:a': 0.72; 'subject:via': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:user-agent:date:subject:from:to:message-id:thread-topic :in-reply-to:mime-version:content-type:content-transfer-encoding; bh=/DrZhuPiE1u0j2kjh9WAcaJtnOoDhUa0TXu5IsOKZ/0=; b=b0cs8nJmEKyjNTZZizc80pEfvwCyVNk6FzDnOPDZ4y0FkilevS2kXh66JMtHFs7m4D mrWWCc7+bHtOvN5r/bgxitKBrDKZuRNGKyPhbJSZu9coPTWuC09EmI3Q7YefzMo1mNzA Caukn/iSs48T0TgXIADo40BZmn1UunvCQHoHFYUBuSvNicwXjP8twvwKd/+oIseMkI/n IvvKZwsBB2zGk6gN53XjcUugZTxGzcrNXev/sH4fqTp1lNAFWDIC9BrR371fyFLxkExo WUZJzeUm2uleZP7l41ubJNV2tVLH+6vRL7usXoCcmJaWTIEJxSAD1ztmvZ27DdTzdRBu bK9w== X-Received: by 10.66.82.35 with SMTP id f3mr78325795pay.49.1360187765850; Wed, 06 Feb 2013 13:56:05 -0800 (PST) User-Agent: Microsoft-MacOutlook/14.3.0.121105 Date: Wed, 06 Feb 2013 13:55:58 -0800 Subject: Re: Curious to see alternate approach on a search/replace via regex From: Demian Brecht To: rh , Thread-Topic: Curious to see alternate approach on a search/replace via regex In-Reply-To: <20130206134105.9352d665e1f8d0719021fcf9@lavabit.com> Mime-version: 1.0 Content-type: text/plain; charset="US-ASCII" Content-transfer-encoding: 7bit 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: 34 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1360187770 news.xs4all.nl 6851 [2001:888:2000:d::a6]:55796 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:38304 Well, an alternative /could/ be: from urlparse import urlparse parts = urlparse('http://alongnameofasite1234567.com/q?sports=run&a=1&b=1') print '%s%s_%s' % (parts.netloc.replace('.', '_'), parts.path.replace('/', '_'), parts.query.replace('&', '_').replace('=', '_') ) Although with the result of: alongnameofasite1234567_com_q_sports_run_a_1_b_1 1288 function calls in 0.004 seconds Compared to regex method: 498 function calls (480 primitive calls) in 0.000 seconds I'd prefer the regex method myself. Demian Brecht http://demianbrecht.github.com On 2013-02-06 1:41 PM, "rh" wrote: >http://alongnameofasite1234567.com/q?sports=run&a=1&b=1