all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Ed Morton <mortonspam@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: Quickie - Regexp for a string not at the beginning of the line
Date: Fri, 26 Oct 2012 07:32:10 -0500	[thread overview]
Message-ID: <k6dvsb$sve$1@dont-email.me> (raw)
In-Reply-To: <d243ac78-ffca-4e93-b2dc-6b30ca7d2586@r6g2000yqd.googlegroups.com>

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.
>



  parent reply	other threads:[~2012-10-26 12:32 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <9eba5652-f814-41fa-83e4-460bca2be264@n16g2000yqi.googlegroups.com>
     [not found] ` <e6f60702-d85f-4aed-bc03-3147bb007ad8@googlegroups.com>
2012-10-26  1:08   ` Quickie - Regexp for a string not at the beginning of the line Rivka Miller
2012-10-26  2:00     ` Ed Morton
2012-10-26  2:11     ` Ben Bacarisse
2012-10-26  4:45       ` Rivka Miller
2012-10-26 12:11         ` Ben Bacarisse
2012-10-26 12:32         ` Ed Morton [this message]
2012-10-26  2:19     ` PJ Weisberg
2012-10-26 12:02       ` Doug Lewan
2012-10-26  3:22     ` anon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='k6dvsb$sve$1@dont-email.me' \
    --to=mortonspam@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.