From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Ed Morton Newsgroups: gmane.emacs.help Subject: Re: Quickie - Regexp for a string not at the beginning of the line Date: Fri, 26 Oct 2012 07:32:10 -0500 Organization: A noiseless patient Spider Message-ID: 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> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1351254916 2934 80.91.229.3 (26 Oct 2012 12:35:16 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 26 Oct 2012 12:35:16 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Oct 26 14:35:20 2012 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1TRj8C-0001ZK-NR for geh-help-gnu-emacs@m.gmane.org; Fri, 26 Oct 2012 14:35:20 +0200 Original-Received: from localhost ([::1]:58494 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TRj84-0007Xi-RE for geh-help-gnu-emacs@m.gmane.org; Fri, 26 Oct 2012 08:35:12 -0400 Original-Path: usenet.stanford.edu!newsfeed.esat.net!feeder.news.heanet.ie!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail Original-Newsgroups: comp.unix.shell, comp.lang.javascript, comp.lang.python, gnu.emacs.help, comp.emacs Original-Lines: 80 Injection-Date: Fri, 26 Oct 2012 12:32:11 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="8db3055794626b3823aefe741b58e5e5"; logging-data="29678"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/Yb8Qr+HkLz5ZD3Kv9k0w5" User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:16.0) Gecko/20121010 Thunderbird/16.0.1 In-Reply-To: Cancel-Lock: sha1:9Td02FeOz0bkzE/tOehin1yNhVY= Original-Xref: usenet.stanford.edu comp.unix.shell:256072 comp.lang.javascript:631052 comp.lang.python:686504 gnu.emacs.help:195117 comp.emacs:102664 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:87446 Archived-At: 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 "$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. >