Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder7.xlned.com!newsfeed.xs4all.nl!newsfeed3a.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.043 X-Spam-Evidence: '*H*': 0.91; '*S*': 0.00; 'string.': 0.05; 'string': 0.09; 'python': 0.11; '"|"': 0.16; '12:59': 0.16; 'backslashes': 0.16; 'notation': 0.16; 'operator.': 0.16; 'subject:Regular': 0.16; 'header:In-Reply-To:1': 0.27; 'character': 0.29; 'message- id:@mail.gmail.com': 0.30; 'too.': 0.31; 'pipe': 0.31; 'regular': 0.32; 'raw': 0.33; 'subject:the': 0.34; 'but': 0.35; 'received:google.com': 0.35; 'hi,': 0.36; 'e.g.': 0.38; 'to:addr :python-list': 0.38; 'sure': 0.39; 'to:addr:python.org': 0.39; 'unable': 0.39; 'expression': 0.60; 'containing': 0.69; 'default': 0.69; 'special': 0.74; 'skip:| 10': 0.84 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 :content-type; bh=ChpBZQsvnVt5BhPrzifTF/9bxPykKMf5t9dhI9WECQk=; b=flQ7yHONdgl01IM+KTAjpJvrX+tRmetg7VYSDqKjlGnHsKBMzcwaVgVvLMe3JXPRB+ bW0pJJ77nqUQK0kKvUqPf92x+huUKR79Isd3xciGo9fOQrbo0lV/Lv3WjYmhPFJC7jeT VFeAgbqXIluktkG2HRfmWj+ZLVwdiAMSXA7WoPv8vmnk1yUM+CekfXV4NTWHdFj4lryE whD7r0Fz0iVC2sZwtLdaTChO0BfuCIeqvjkpu3LGOK9pX6pJgT2m950hrikkrSplQJbN bJgxow4eR8ITZY6esI4/rK8VTC5oZ0j3UMraJdIBVfRjieueSmiSMdVC8iFxe3fXhaEQ WzTg== MIME-Version: 1.0 X-Received: by 10.229.220.197 with SMTP id hz5mr40969583qcb.9.1401188959719; Tue, 27 May 2014 04:09:19 -0700 (PDT) In-Reply-To: <9c8e58be-9619-44c7-8098-961a0134c422@googlegroups.com> References: <9c8e58be-9619-44c7-8098-961a0134c422@googlegroups.com> Date: Tue, 27 May 2014 13:09:19 +0200 Subject: Re: Regular Expression for the special character "|" pipe From: Vlastimil Brom To: python Content-Type: text/plain; charset=UTF-8 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: 24 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1401188967 news.xs4all.nl 2902 [2001:888:2000:d::a6]:47256 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:72110 2014-05-27 12:59 GMT+02:00 Aman Kashyap : > I would like to create a regular expression in which i can match the "|" special character too. > > e.g. > > start=|ID=ter54rt543d|SID=ter54rt543d|end=| > > I want to only |ID=ter54rt543d| from the above string but i am unable to write the pattern match containing "|" pipe too. > > By default python treat "|" as an OR operator. > > But in my case I want to use to as a part of search string. > -- Hi, you can just escpape the pipe with backlash like any other metacharacter: r"start=\|ID=ter54rt543d" be sure to use the raw string notation r"...", or you can double all backslashes in the string. hth, vbr