all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* problem re-search with the \| op.
@ 2008-01-10 20:44 rtra
  2008-01-11  3:35 ` Barry Margolin
  0 siblings, 1 reply; 2+ messages in thread
From: rtra @ 2008-01-10 20:44 UTC (permalink / raw)
  To: help-gnu-emacs

Hi,

I'm having problems searching for a regular expression matching two
alternatives, A or B.
A = "#title "
B = "\* [A-Z][a-z]+.*"
and allow '.' (dot) to be string concatenation

(re-search-backward A 1 t) matches the string A as I intended, and
(re-search-backward B 1 t) also matches B as intended, but
(re-search-backward A."\|".B 1 t) does not matches A or B as I thought
it should

I'm using GNU Emacs 22.1.1, and testing this with a file like
----8<----
#title test
* tset

<point is here>
----8<----

Thank you for you time.
(I've wasted some in the manual, but I'm not figuring this out...)

Rui Almeida

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

* Re: problem re-search with the \| op.
  2008-01-10 20:44 problem re-search with the \| op rtra
@ 2008-01-11  3:35 ` Barry Margolin
  0 siblings, 0 replies; 2+ messages in thread
From: Barry Margolin @ 2008-01-11  3:35 UTC (permalink / raw)
  To: help-gnu-emacs

In article 
<ce71df65-e69f-415b-8d7a-721782e4445f@d70g2000hsb.googlegroups.com>,
 rtra <ruitra@gmail.com> wrote:

> Hi,
> 
> I'm having problems searching for a regular expression matching two
> alternatives, A or B.
> A = "#title "
> B = "\* [A-Z][a-z]+.*"
> and allow '.' (dot) to be string concatenation

'.' is string concatenation in Perl, not Lisp.  Lisp does everything 
using functions, not operators like this.  The string concatenation 
function is concat.

> 
> (re-search-backward A 1 t) matches the string A as I intended, and
> (re-search-backward B 1 t) also matches B as intended, but
> (re-search-backward A."\|".B 1 t) does not matches A or B as I thought
> it should

(re-search-backward (concat a "\\|" b) 1 t)

You need to escape the backslash because it has a special meaning in 
strings.

> 
> I'm using GNU Emacs 22.1.1, and testing this with a file like
> ----8<----
> #title test
> * tset
> 
> <point is here>
> ----8<----
> 
> Thank you for you time.
> (I've wasted some in the manual, but I'm not figuring this out...)
> 
> Rui Almeida

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

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

end of thread, other threads:[~2008-01-11  3:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-01-10 20:44 problem re-search with the \| op rtra
2008-01-11  3:35 ` Barry Margolin

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.