all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Searching for a string in a string
@ 2009-09-28 12:54 Nordlöw
  2009-09-28 12:57 ` Pascal J. Bourguignon
  2009-09-28 12:59 ` Joost Kremers
  0 siblings, 2 replies; 4+ messages in thread
From: Nordlöw @ 2009-09-28 12:54 UTC (permalink / raw)
  To: help-gnu-emacs

Is there a variant of string-match() that searches for a string (sub-
string) instead of a regexp?

/Nordlöw


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

* Re: Searching for a string in a string
  2009-09-28 12:54 Searching for a string in a string Nordlöw
@ 2009-09-28 12:57 ` Pascal J. Bourguignon
  2009-09-28 12:59 ` Joost Kremers
  1 sibling, 0 replies; 4+ messages in thread
From: Pascal J. Bourguignon @ 2009-09-28 12:57 UTC (permalink / raw)
  To: help-gnu-emacs

Nordlöw <per.nordlow@gmail.com> writes:

> Is there a variant of string-match() that searches for a string (sub-
> string) instead of a regexp?

(defun literal-string-match (substring string &optional start)
   (string-match (regexp-quote substring) string (or start 0)))

(literal-string-match "..?" "Hello? world..? ah!") --> 12


-- 
__Pascal Bourguignon__


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

* Re: Searching for a string in a string
  2009-09-28 12:54 Searching for a string in a string Nordlöw
  2009-09-28 12:57 ` Pascal J. Bourguignon
@ 2009-09-28 12:59 ` Joost Kremers
  2009-09-28 13:08   ` Pascal J. Bourguignon
  1 sibling, 1 reply; 4+ messages in thread
From: Joost Kremers @ 2009-09-28 12:59 UTC (permalink / raw)
  To: help-gnu-emacs

Nordlöw wrote:
> Is there a variant of string-match() that searches for a string (sub-
> string) instead of a regexp?

a string is just a special case of a regexp, so why wouldn't you use
string-match?


-- 
Joost Kremers                                      joostkremers@yahoo.com
Selbst in die Unterwelt dringt durch Spalten Licht
EN:SiS(9)


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

* Re: Searching for a string in a string
  2009-09-28 12:59 ` Joost Kremers
@ 2009-09-28 13:08   ` Pascal J. Bourguignon
  0 siblings, 0 replies; 4+ messages in thread
From: Pascal J. Bourguignon @ 2009-09-28 13:08 UTC (permalink / raw)
  To: help-gnu-emacs

Joost Kremers <joostkremers@yahoo.com> writes:

> Nordlöw wrote:
>> Is there a variant of string-match() that searches for a string (sub-
>> string) instead of a regexp?
>
> a string is just a special case of a regexp, so why wouldn't you use
> string-match?

A primitive literal-string-match could be more efficient than a
generic regular expression matching algorithm.  That said, if the
regexp machinery is well optimized, we only lose regexp compilation
time, which in the case of a fully escaped regular expression may be
very fast.

-- 
__Pascal Bourguignon__


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

end of thread, other threads:[~2009-09-28 13:08 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-09-28 12:54 Searching for a string in a string Nordlöw
2009-09-28 12:57 ` Pascal J. Bourguignon
2009-09-28 12:59 ` Joost Kremers
2009-09-28 13:08   ` Pascal J. Bourguignon

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.