Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #32214
| 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 | <joel.goldstick@gmail.com> |
| 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 | <k6dvsb$sve$1@dont-email.me> |
| References | <9eba5652-f814-41fa-83e4-460bca2be264@n16g2000yqi.googlegroups.com> <e6f60702-d85f-4aed-bc03-3147bb007ad8@googlegroups.com> <73f60cf3-d932-4366-a405-6767488560c6@q16g2000yqc.googlegroups.com> <0.485c579271f72431d3a7.20121026031110BST.87k3ue7zk1.fsf@bsb.me.uk> <d243ac78-ffca-4e93-b2dc-6b30ca7d2586@r6g2000yqd.googlegroups.com> <k6dvsb$sve$1@dont-email.me> |
| 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 <joel.goldstick@gmail.com> |
| To | Ed Morton <mortonspam@gmail.com> |
| 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 <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2891.1351256027.27098.python-list@python.org> (permalink) |
| 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 |
Show key headers only | View raw
On Fri, Oct 26, 2012 at 8:32 AM, Ed Morton <mortonspam@gmail.com> 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 "<any
> 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
> <whatever>".
>
> 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 <ben.use...@bsb.me.uk> wrote:
>>>
>>> Rivka Miller <rivkaumil...@gmail.com> writes:
>>>>
>>>> On Oct 25, 2:27 pm, Danny <dann90...@gmail.com> 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/(?<!^)\$hello\$/XXX/
>>>
>>>> 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.
>>>
>>> <snip>
>>> --
>>> 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
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Quickie - Regexp for a string not at the beginning of the line Rivka Miller <rivkaumiller@gmail.com> - 2012-10-25 13:53 -0700
Re: Quickie - Regexp for a string not at the beginning of the line Janis Papanagnou <janis_papanagnou@hotmail.com> - 2012-10-25 23:01 +0200
Re: Quickie - Regexp for a string not at the beginning of the line Zero Piraeus <schesis@gmail.com> - 2012-10-25 17:21 -0400
Re: Quickie - Regexp for a string not at the beginning of the line Rivka Miller <rivkaumiller@gmail.com> - 2012-10-25 18:08 -0700
Re: Quickie - Regexp for a string not at the beginning of the line Dave Angel <d@davea.name> - 2012-10-25 21:21 -0400
Re: Quickie - Regexp for a string not at the beginning of the line Ed Morton <mortonspam@gmail.com> - 2012-10-25 21:00 -0500
Re: Quickie - Regexp for a string not at the beginning of the line Devin Jeanpierre <jeanpierreda@gmail.com> - 2012-10-26 01:08 -0400
Re: Quickie - Regexp for a string not at the beginning of the line Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-10-26 03:11 +0100
Re: Quickie - Regexp for a string not at the beginning of the line Rivka Miller <rivkaumiller@gmail.com> - 2012-10-25 21:45 -0700
Re: Quickie - Regexp for a string not at the beginning of the line Janis Papanagnou <janis_papanagnou@hotmail.com> - 2012-10-26 11:18 +0200
Re: Quickie - Regexp for a string not at the beginning of the line Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-10-26 13:11 +0100
Re: Quickie - Regexp for a string not at the beginning of the line Ed Morton <mortonspam@gmail.com> - 2012-10-26 07:32 -0500
Re: Quickie - Regexp for a string not at the beginning of the line Joel Goldstick <joel.goldstick@gmail.com> - 2012-10-26 08:53 -0400
Re: Quickie - Regexp for a string not at the beginning of the line MRAB <python@mrabarnett.plus.com> - 2012-10-26 03:11 +0100
Re: Quickie - Regexp for a string not at the beginning of the line David Hutto <dwightdhutto@gmail.com> - 2012-10-25 23:02 -0400
Re: Quickie - Regexp for a string not at the beginning of the line anon@anon.anon - 2012-10-25 23:22 -0400
Re: Quickie - Regexp for a string not at the beginning of the line Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-10-26 03:37 +0100
Re: Quickie - Regexp for a string not at the beginning of the line Asen Bozhilov <asen.bozhilov@gmail.com> - 2012-10-26 03:46 -0700
csiph-web