help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


From: Ben Bacarisse
Subject: Re: Quickie - Regexp for a string not at the beginning of the line
Date: Fri, 26 Oct 2012 03:11:10 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux)

Rivka Miller <rivkaumiller@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.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]