all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Anchoring a RE in a string
@ 2012-06-08 18:48 Doug Lewan
  2012-06-08 19:08 ` Doug Lewan
       [not found] ` <mailman.2452.1339182516.855.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 8+ messages in thread
From: Doug Lewan @ 2012-06-08 18:48 UTC (permalink / raw
  To: help-gnu-emacs@gnu.org

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





^ permalink raw reply	[flat|nested] 8+ messages in thread

* RE: Anchoring a RE in a string
  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>
  1 sibling, 0 replies; 8+ messages in thread
From: Doug Lewan @ 2012-06-08 19:08 UTC (permalink / raw
  To: help-gnu-emacs@gnu.org

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




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Anchoring a RE in a string
       [not found] ` <mailman.2452.1339182516.855.help-gnu-emacs@gnu.org>
@ 2012-06-08 19:18   ` jpkotta
  2012-06-08 21:06     ` Doug Lewan
  0 siblings, 1 reply; 8+ messages in thread
From: jpkotta @ 2012-06-08 19:18 UTC (permalink / raw
  To: gnu.emacs.help; +Cc: 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.



^ permalink raw reply	[flat|nested] 8+ messages in thread

* RE: Anchoring a RE in a string
  2012-06-08 19:18   ` jpkotta
@ 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>
  0 siblings, 2 replies; 8+ messages in thread
From: Doug Lewan @ 2012-06-08 21:06 UTC (permalink / raw
  To: help-gnu-emacs@gnu.org

\` -- empty string at the beginning of buffer

Fantastic!

In fact, I'd found my first use for \' just recently. I don't know why it didn't strike me.

I will never run out of things to learn in emacs. As a video game, I still feel like I'm on level 2.

> -----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 jpkotta
> Sent: Friday, 2012 June 08 15:19
> To: gnu.emacs.help@googlegroups.com
> Cc: help-gnu-emacs@gnu.org
> Subject: Re: Anchoring a RE in a string
> 
> 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.




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Anchoring a RE in a string
  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>
  1 sibling, 0 replies; 8+ messages in thread
From: Philipp Haselwarter @ 2012-06-09 19:28 UTC (permalink / raw
  To: help-gnu-emacs

`rx' is cool when you're too lazy to look up special symbols


-- 
Philipp Haselwarter




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Anchoring a RE in a string
       [not found]       ` <mailman.2517.1339270124.855.help-gnu-emacs@gnu.org>
@ 2012-06-10  5:38         ` rusi
  2012-06-10  7:06           ` Philipp Haselwarter
  0 siblings, 1 reply; 8+ messages in thread
From: rusi @ 2012-06-10  5:38 UTC (permalink / raw
  To: help-gnu-emacs

On Jun 10, 12:28 am, Philipp Haselwarter <phil...@haselwarter.org>
wrote:
> `rx' is cool when you're too lazy to look up special symbols
>
> --
> Philipp Haselwarter

Interesting!! Cant find an info page.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Anchoring a RE in a string
  2012-06-10  5:38         ` rusi
@ 2012-06-10  7:06           ` Philipp Haselwarter
  2012-06-10 14:34             ` Drew Adams
  0 siblings, 1 reply; 8+ messages in thread
From: Philipp Haselwarter @ 2012-06-10  7:06 UTC (permalink / raw
  To: help-gnu-emacs

On Sun, Jun 10 2012 07:38 (@1339306698), rusi wrote:

> On Jun 10, 12:28 am, Philipp Haselwarter <phil...@haselwarter.org>
> wrote:
>> `rx' is cool when you're too lazy to look up special symbols
>>
>> --
>> Philipp Haselwarter
>
> Interesting!! Cant find an info page.
>

Unfortunately, its only mention in emacs or elisp info is Gerd
Moellmann's authorship notice: "[...] `rx.el', a regular expression
constructor. ".

Take a look at C-h f rx RET

-- 
Philipp Haselwarter




^ permalink raw reply	[flat|nested] 8+ messages in thread

* RE: Anchoring a RE in a string
  2012-06-10  7:06           ` Philipp Haselwarter
@ 2012-06-10 14:34             ` Drew Adams
  0 siblings, 0 replies; 8+ messages in thread
From: Drew Adams @ 2012-06-10 14:34 UTC (permalink / raw
  To: 'Philipp Haselwarter', help-gnu-emacs

> Unfortunately, its only mention in emacs or elisp info is Gerd
> Moellmann's authorship notice: "[...] `rx.el', a regular expression
> constructor. ".  Take a look at C-h f rx RET

If you cannot find something in the manuals, try searching for it at EmacsWiki
(or Google after that).  Entering "rx" in the wiki search field shows this page
as the first search hit: http://emacswiki.org/emacs/rx.

(That of course is not intended to mean that something should not also be
mentioned in the manuals.  It's just intended to help you find information.  The
wiki is another resource, like help-gnu-emacs@gnu.org.)




^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2012-06-10 14:34 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

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.