unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: jpkotta <jpkotta@gmail.com>
To: gnu.emacs.help@googlegroups.com
Cc: "help-gnu-emacs@gnu.org" <help-gnu-emacs@gnu.org>
Subject: Re: Anchoring a RE in a string
Date: Fri, 8 Jun 2012 12:18:45 -0700 (PDT)	[thread overview]
Message-ID: <16e6a48b-6b6c-46dd-b686-7a1a6dd944d6@googlegroups.com> (raw)
In-Reply-To: <mailman.2452.1339182516.855.help-gnu-emacs@gnu.org>

On Friday, June 8, 2012 2:08:24 PM UTC-5, Doug Lewan wrote:
> I've found the /adequate/ solution.
> 
> (setq s (delete ?\n s))
> (string-match "^\\s-+ABCD" s)
> 
> Still, is there no way of truly anchoring at the beginning of a string?
> 
> > -----Original Message-----
> > From: help-gnu-emacs-bounces+dougl=shubertticketing.com@gnu.org
> > [mailto:help-gnu-emacs-bounces+dougl=shubertticketing.com@gnu.org] On
> > Behalf Of Doug Lewan
> > Sent: Friday, 2012 June 08 14:49
> > To: help-gnu-emacs@gnu.org
> > Subject: Anchoring a RE in a string
> > 
> > Currently I'm trying to check the /beginning/ of a multi-line string
> > with a regular expression.
> > The scenario looks like this:
> > 
> > (string-match "^\\s-+ABCD"
> >               "qwer\n    zxcv\n    ABCD")
> >                                             ^ Matches here.
> > 
> > I want it to fail because the beginning doesn't match.
> > I hadn't expected the anchor (^) to match inside the string.
> > 
> > I can't be the only one to have wanted to do this.
> > What's the right way.
> > 
> > Thanks.
> > 
> > ,Douglas
> > Douglas Lewan
> > Shubert Ticketing
> > (201) 489-8600 ext 224
> > 
> >

Use \\` instead of ^.  See "34.3.1.1 Special Characters in Regular Expressions" in the Elisp manual.



  parent reply	other threads:[~2012-06-08 19:18 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-08 18:48 Anchoring a RE in a string Doug Lewan
2012-06-08 19:08 ` Doug Lewan
     [not found] ` <mailman.2452.1339182516.855.help-gnu-emacs@gnu.org>
2012-06-08 19:18   ` jpkotta [this message]
2012-06-08 21:06     ` Doug Lewan
2012-06-09 19:28       ` Philipp Haselwarter
     [not found]       ` <mailman.2517.1339270124.855.help-gnu-emacs@gnu.org>
2012-06-10  5:38         ` rusi
2012-06-10  7:06           ` Philipp Haselwarter
2012-06-10 14:34             ` Drew Adams

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=16e6a48b-6b6c-46dd-b686-7a1a6dd944d6@googlegroups.com \
    --to=jpkotta@gmail.com \
    --cc=gnu.emacs.help@googlegroups.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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).