[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: "C-a" the first character in each line?
From: |
Barry Margolin |
Subject: |
Re: "C-a" the first character in each line? |
Date: |
Sun, 24 Jun 2007 21:32:53 -0400 |
User-agent: |
MT-NewsWatcher/3.5.2 (PPC Mac OS X) |
In article <1182693577.251257.35950@u2g2000hsc.googlegroups.com>,
weber <hugows@gmail.com> wrote:
> On Jun 24, 10:20 am, Nikos Apostolakis <nikos...@gmail.com> wrote:
> > Hello group,
> >
> > in the scratch buffer I did
> >
> > -----------------
> > (while (search-forward-regexp "^\\(.\\)" nil t)
> > (replace-match "\% \1"))
> >
> > laa
> > moo
> > nii
> > -----------------
> >
> > I expected
> >
> > %
> > % laa
> > % moo
> > % nii
> >
> > but isnstead I get
> >
> > % ^A
> > % ^Aaa
> > % ^Aoo
> > % ^Aii
> >
> > where ^A stands for the character "C-a".
> >
> > What am I missing?
> >
> > TIA,
> > Nikos
>
> Dunno why, but \\1 instead of \1 solves it.
Because \ is used as an escape prefix for both Elisp strings and regular
expressions. It's first processed by the Elisp string parser, which
uses \<number> to represent characters by their ASCII code, and \\ to
represent a literal \. You need to use the latter to get the \ passed
through to the regexp processor.
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***