🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.unix.shell
Article #4080

Re: Quickie - Regexp for a string not at the beginning of the line

#4080
From: Rivka Miller
Date: Fri, 26 Oct 2012 04:45
65 lines
4309 bytes
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. 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.
Technical Details
Message-ID: <d243ac78-ffca-4e93-b2dc-6b30ca7d2586@r6g2000yqd.googlegroups.com>
Path: arc1-ca.pugleaf.net!r17ni69121101qap.0!nntp.google.com!x14no8576547qar.0!postnews.google.com!r6g2000yqd.googlegroups.com!not-for-mail
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>

Show Full Headers
Complete Article Headers
X-Google-Thread: 1012a6,9a5a8b7965caac8b
X-Google-NewGroupId: yes
X-Google-Thread: fb3cb,9a5a8b7965caac8b
X-Google-NewGroupId: yes
X-Google-Thread: 10dd18,9a5a8b7965caac8b
X-Google-NewGroupId: yes
X-Google-Thread: 103b8b,540e62bbe775c345
X-Google-NewGroupId: yes
X-Google-Thread: 102b9a,540e62bbe775c345
X-Google-NewGroupId: yes
X-Google-Attributes: gid9d2148d7bf,gid559884fbb1,gidc8df1ae2c2,gid39ae015015,gid853c49a5d,domainid0,public,usenet
X-Google-Language: ENGLISH,ASCII
Received: by 10.224.138.142 with SMTP id a14mr11090137qau.4.1351226705206;
        Thu, 25 Oct 2012 21:45:05 -0700 (PDT)
MIME-Version: 1.0
Received: by 10.236.116.67 with SMTP id f43mr1758170yhh.13.1351226705122; Thu,
 25 Oct 2012 21:45:05 -0700 (PDT)
Path: arc1-ca.pugleaf.net!r17ni69121101qap.0!nntp.google.com!x14no8576547qar.0!postnews.google.com!r6g2000yqd.googlegroups.com!not-for-mail
Newsgroups: comp.unix.shell,comp.lang.javascript,comp.lang.python,gnu.emacs.help,comp.emacs
Date: Thu, 25 Oct 2012 21:45:05 -0700 (PDT)
Complaints-To: groups-abuse@google.com
Injection-Info: r6g2000yqd.googlegroups.com; posting-host=99.42.77.183; posting-account=V5Tx-QoAAACNTDxOswIwdOklJAUE-vym
NNTP-Posting-Host: 99.42.77.183
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>
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Windows NT 5.1; rv:12.0) Gecko/20100101 Firefox/12.0,gzip(gfe)
Message-ID: <d243ac78-ffca-4e93-b2dc-6b30ca7d2586@r6g2000yqd.googlegroups.com>
Subject: Re: Quickie - Regexp for a string not at the beginning of the line
From: Rivka Miller <rivkaumiller@gmail.com>
Injection-Date: Fri, 26 Oct 2012 04:45:05 +0000
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable