all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* help with Regexps
@ 2009-05-11  3:12 Santiago Mejia
  0 siblings, 0 replies; 3+ messages in thread
From: Santiago Mejia @ 2009-05-11  3:12 UTC (permalink / raw)
  To: help-gnu-emacs


I have a file that has these three types of entries (they all appear in
the beginning of the line).

1. %\card{\word{Mutter}}{mom, mommy, mother, nut}
2. \card{\atl{die} \word{Erkenntnis}}{cognition, cognizance, perception}
3. \card{\word{Jünglinge}}{teens, younglings}

And I want to be able to use (search-forward-regexp ???) within a
function to find only 3. (and not 1. and 2).

When I try: (search-forward-regexp "^\\card{\\word{[A-Z]"), emacs
complains: Search failed: "^\\card{\\word{[A-Z]" (in fact, even
(search-forward-regexp "^\\card") fails to find anything).  What am I
making wrong?

I could also solve the issue by excluding a particular string
(in this case "\atl") from a search.  How can one do this?

I read through the info, and tried searching on Google, but I was not
able to find a solution to either attempt.  It is probably there
(probably even in the info I read), but I was not able to sort it out.

Thanks in advance for any help.

Santiago.

P.D.  I tried posting this in the newsgroups, but it seems that there
was a problem, since I do not see my question appearing there.





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

* Re: help with Regexps
       [not found] <mailman.6983.1242027435.31690.help-gnu-emacs@gnu.org>
@ 2009-05-11  8:33 ` Anselm Helbig
  2009-05-11 17:59   ` Santiago Mejia
  0 siblings, 1 reply; 3+ messages in thread
From: Anselm Helbig @ 2009-05-11  8:33 UTC (permalink / raw)
  To: help-gnu-emacs

Hi!

> I have a file that has these three types of entries (they all appear in
> the beginning of the line).
> 
> 1. %\card{\word{Mutter}}{mom, mommy, mother, nut}
> 2. \card{\atl{die} \word{Erkenntnis}}{cognition, cognizance, perception}
> 3. \card{\word{Jünglinge}}{teens, younglings}
> 
> And I want to be able to use (search-forward-regexp ???) within a
> function to find only 3. (and not 1. and 2).
> 
> When I try: (search-forward-regexp "^\\card{\\word{[A-Z]"), emacs
> complains: Search failed: "^\\card{\\word{[A-Z]" (in fact, even
> (search-forward-regexp "^\\card") fails to find anything).  What am I
> making wrong?

You have to quote the backslashes twice, the first time for the lisp
string and then for the regex:

  (search-forward-regexp "^\\\\card{\\\\word{[A-Z]")

Ugly, but consistent. 

HTH, 

Anselm


-- 
Anselm Helbig 
mailto:anselm.helbig+news2009@googlemail.com


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

* Re: help with Regexps
  2009-05-11  8:33 ` help with Regexps Anselm Helbig
@ 2009-05-11 17:59   ` Santiago Mejia
  0 siblings, 0 replies; 3+ messages in thread
From: Santiago Mejia @ 2009-05-11 17:59 UTC (permalink / raw)
  To: help-gnu-emacs


> I am still curious about the second alternative.  Do you, by any chance,
> know how to have regexp exclude a particular string (in this case,
> "\atl") from a search?

Regular expressions are bad at excluding things. You can try to do it
but it gets ugly very soon. I'd rather insert a second step, so your
program would look like this:

  (while (search-forward-regexp "^\\\\card{")
    (when (not (looking-at "\\\\atl"))
      (do-some-stuff)))
    
HTH, 

Anselm





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

end of thread, other threads:[~2009-05-11 17:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.6983.1242027435.31690.help-gnu-emacs@gnu.org>
2009-05-11  8:33 ` help with Regexps Anselm Helbig
2009-05-11 17:59   ` Santiago Mejia
2009-05-11  3:12 Santiago Mejia

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.