Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!newsfeed.eweka.nl!eweka.nl!feeder3.eweka.nl!newsfeed.xs4all.nl!newsfeed5.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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'syntax': 0.03; 'output': 0.04; 'string.': 0.04; 'matches': 0.07; 'perl,': 0.07; 'subject:string': 0.09; 'cc:addr:python-list': 0.10; 'subject:not': 0.11; 'suggest': 0.11; 'index': 0.13; 'yet.': 0.13; 'ignore': 0.13; 'language': 0.14; 'received:74.125.82.44': 0.15; 'danny': 0.16; 'ed.': 0.16; 'esp': 0.16; 'example)': 0.16; 'literal.': 0.16; 'oct': 0.16; 'really?': 0.16; 'sed': 0.16; 'two,': 0.16; 'string': 0.17; 'wrote:': 0.17; 'char': 0.17; 'everyone,': 0.17; 'found,': 0.17; 'specify': 0.17; 'examples': 0.18; 'saying': 0.18; '>>>': 0.18; 'translate': 0.20; 'versions': 0.20; 'universal': 0.22; 'cc:2**0': 0.23; 'matching': 0.23; 'cc:no real name:2**0': 0.24; 'second': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'common': 0.26; 'am,': 0.27; 'replace': 0.27; 'message-id:@mail.gmail.com': 0.27; 'this?': 0.28; 'fine': 0.28; '>>>>': 0.29; 'character.': 0.29; 'finds': 0.29; 'perl': 0.29; 'preceding': 0.29; 'prints': 0.29; 'writes:': 0.29; 'url:mailman': 0.29; 'maybe': 0.29; 'usually': 0.30; 'worked': 0.30; 'e.g.': 0.30; 'fri,': 0.30; 'expect': 0.31; 'code': 0.31; 'url:python': 0.32; "skip:' 20": 0.32; 'print': 0.32; 'url:listinfo': 0.32; 'received:74.125.82': 0.33; 'anywhere': 0.33; "can't": 0.34; 'received:google.com': 0.34; 'text': 0.34; 'wrong': 0.34; 'thanks': 0.34; 'whatever': 0.35; 'ben': 0.35; 'pm,': 0.35; 'posting': 0.35; 'similar': 0.35; 'really': 0.36; 'ability': 0.36; 'tool': 0.36; 'but': 0.36; 'received:74.125': 0.36; 'url:org': 0.36; 'should': 0.36; 'does': 0.37; 'why': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'possible.': 0.38; 'header:Received:5': 0.40; 'help': 0.40; 'url:mail': 0.40; 'your': 0.60; "you've": 0.61; 'first': 0.61; 'engines': 0.62; 'different': 0.63; 'more': 0.63; 'dont': 0.64; '26,': 0.65; 'reply': 0.66; 'miller': 0.69; 'answer.': 0.71; 'obvious': 0.71; 'saw': 0.75; '100': 0.78; 'satisfied': 0.83; '11:45': 0.84; 'modify.': 0.84; 'returns.': 0.84; 'joel': 0.91; 'tied': 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=5bYJdcxKcatZgBKsMZxUCdSSLdDSu/EbpZ5sCImeIwk=; b=dV2WPWSybVecQK97+r6E+THUK5HseLg1NBI8nQKprM7hXM2EV1ukaE+La3q3IvybVO H8y/kmV88/0bjWaZSKZRkQORf93gdk2W4X3Jlrc0UGZaZ3HxR6ybA5dAL0Gr1gAmoq+1 7cwf1IiT1PlcJ+gBeWqA4csJhW/t/Cae21A2wrJ5mNCWAVS5E0Lay4F/PjZSQ8XevFCH YonbgiuqohaGN3wDRPVsvpXTu0XJBBSsWMVtaqk6+8b53+cBLaFBTwQqlVWzJ0Dq7ZJA PIFeLrNKi/N/x1A7tgL5/eRw32QcjvHYnEodPTkMA8kEM+7Q7RNqnJMvU1ji0ttIymq2 ToDQ== MIME-Version: 1.0 In-Reply-To: References: <9eba5652-f814-41fa-83e4-460bca2be264@n16g2000yqi.googlegroups.com> <73f60cf3-d932-4366-a405-6767488560c6@q16g2000yqc.googlegroups.com> <0.485c579271f72431d3a7.20121026031110BST.87k3ue7zk1.fsf@bsb.me.uk> Date: Fri, 26 Oct 2012 08:53:44 -0400 Subject: Re: Quickie - Regexp for a string not at the beginning of the line From: Joel Goldstick To: Ed Morton 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: 107 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1351256027 news.xs4all.nl 6929 [2001:888:2000:d::a6]:52549 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:32214 On Fri, Oct 26, 2012 at 8:32 AM, Ed Morton wrote: > On 10/25/2012 11:45 PM, Rivka Miller wrote: >> >> Thanks everyone, esp this gentleman. >> >> The solution that worked best for me is just to use a DOT before the >> string as the one at the beginning of the line did not have any char >> before it. > > > That's fine but do you understand that that is not an RE that matches on > "$hello$ not at the start of a line", it's an RE that matches on " char>$hello$ anywhere in the line"? There's a difference - if you use a tool > that prints the text that matches an RE then the output if the first RE > existed would be "$hello$" while the output for the second RE would be > "X$hello$" or "Y$hello$" or.... > > In some tools you can use /(.)$hello$/ or similar to ignore the first part > of the RE "(.)" and just print the second "$hello", but that ability and > it's syntax is tool-specific, you still can't say "here's an RE that does > this", you've got to say "here's how to find this text using tool > ". > > Ed. > > >> I guess, this requires the ability to ignore the CARAT as the beginning of >> the line. >> >> I am a satisfied custormer. No need for returns. :) >> >> On Oct 25, 7:11 pm, Ben Bacarisse wrote: >>> >>> Rivka Miller writes: >>>> >>>> On Oct 25, 2:27 pm, Danny wrote: >>>>> >>>>> Why you just don't give us the string/input, say a line or two, and >>>>> what you want off of it, so we can tell better what to suggest >>> >>> >>>> no one has really helped yet. >>> >>> >>> Really? I was going to reply but then I saw Janis had given you the >>> answer. If it's not the answer, you should just reply saying what it is >>> that's wrong with it. >>> >>>> I want to search and modify. >>> >>> >>> Ah. That was missing from the original post. You can't expect people >>> to help with questions that weren't asked! To replace you will usually >>> have to capture the single preceding character. E.g. in sed: >>> >>> sed -e 's/\(.\)$hello\$/\1XXX/' >>> >>> but some RE engines (Perl's, for example) allow you specify zero-width >>> assertions. You could, in Perl, write >>> >>> s/(?<=.)\$hello\$/XXX/ >>> >>> without having to capture whatever preceded the target string. But >>> since Perl also has negative zero-width look-behind you can code your >>> request even more directly: >>> >>> s/(?>> >>>> I dont wanna be tied to a specific language etc so I just want a >>>> regexp and as many versions as possible. Maybe I should try in emacs >>>> and so I am now posting to emacs groups also, although javascript has >>>> rich set of regexp facilities. >>> >>> >>> You can't always have a universal solution because different PE >>> implementations have different syntax and semantics, but you should be >>> able to translate Janis's solution of matching *something* before your >>> target into every RE implementation around. >>> >>>> examples >>> >>> >>>> $hello$ should not be selected but >>>> not hello but all of the $hello$ and $hello$ ... $hello$ each one >>>> selected >>> >>> >>> I have taken your $s to be literal. That's not 100 obvious since $ is a >>> common (universal?) RE meta-character. >>> >>> >>> -- >>> Ben. >> >> > > -- > http://mail.python.org/mailman/listinfo/python-list I would use str.find('your string') It returns -1 if not found, and the index if it finds it. why use regex for this? -- Joel Goldstick