From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Tim X Newsgroups: gmane.emacs.help Subject: Re: Regexp issue Date: Sun, 21 Jun 2009 11:14:57 +1000 Organization: Rapt Technologies Message-ID: <87zlc2s7zi.fsf@lion.rapttech.com.au> References: <1245487152.15610.0.camel@drserver> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1245548441 7052 80.91.229.12 (21 Jun 2009 01:40:41 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 21 Jun 2009 01:40:41 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Jun 21 03:40:39 2009 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1MIC2x-0007QW-8E for geh-help-gnu-emacs@m.gmane.org; Sun, 21 Jun 2009 03:40:39 +0200 Original-Received: from localhost ([127.0.0.1]:35506 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MIC2w-0001Yf-Np for geh-help-gnu-emacs@m.gmane.org; Sat, 20 Jun 2009 21:40:38 -0400 Original-Path: news.stanford.edu!headwall.stanford.edu!news.glorb.com!news2.glorb.com!news.astraweb.com!border2.newsrouter.astraweb.com!not-for-mail Original-Newsgroups: gnu.emacs.help User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.95 (gnu/linux) Cancel-Lock: sha1:gEPGLdLHqac06Z9ZVTEDfywOSB0= Original-Lines: 51 Original-NNTP-Posting-Host: 9755bfbf.news.astraweb.com Original-X-Trace: DXC=LA64jYPDAWbTbP Original-Xref: news.stanford.edu gnu.emacs.help:170189 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:65410 Archived-At: Peter Dyballa writes: > Am 20.06.2009 um 14:47 schrieb Alan Mackenzie: > >> But even that will "fail" if point is at "=" in "<=>", for some >> reasonable value of "fail". > > > When point is in the middle of the string to be found it has always to > fail, because the search goes forward from point and never looks back and > therefore it oversees the start of the string to be found. > > -- Given the specs provided by the OP, I think both regexp are correct. To avoid more confusion, we need to be careful not to make too many assumptions. For example, we are asuming the regexp is to be used with search forward in a buffer, a reasonable assumption. It is also possible the regexp is to be used on a string or in a reverse search or .... What I liked about Alan's first example was that he attempted to find an anchor for the string. This is important in regexp as without any anchors, a regexp can become extremely inefficient due to backtracking. For the OP, if you want something more specific, we will need more details on the way the regexp is to be used and the format of the data being processed. The main point in the examples given is that you can exclude something from a match by using a negated set/range using the [] syntax with the first character being the ^. i.e. [^=]. If the pattern to match has other specific characteristics, such as only occuring at the beginning of the line, then Alan's example anchoring the match at the start of the line works well, if it has to match at the end, then using the $ will work. Perhaps it just has to be => with whitespace on each side, in which case you could do "\s=>\s" etc. My recommendation would be to open the data file and use re-builder and experiment until you get the result you want ,----[ C-h f re-builder RET ] | re-builder is an interactive autoloaded Lisp function in `re-builder.el'. | | (re-builder) | | Construct a regexp interactively. `---- -- tcross (at) rapttech dot com dot au