Re: String search vs regexp search

From: Jeremy Fincher (tweedgeezer_at_hotmail.com)
Date: 10/14/03


Date: 13 Oct 2003 21:19:12 -0700

Duncan Booth <duncan@NOSPAMrcp.co.uk> wrote in message news:<Xns941360C9B9445duncanrcpcouk@127.0.0.1>...
> The regular expression code has a startup penalty since it has to compile
> the regular expression at least once, however the actual searching may be
> faster than the naive str.find. If the time spent doing the search is
> sufficiently long compared with the time doing the compile, the regular
> expression may win out.

Both regular expression searching and string.find will do searching
one character at a time; given that, it seems impossible to me that
the hand-coded-in-C "naive" string.find could be slower than the
machine-translated-coded-in-Python regular expression search.
Compilation time only serves to further increase string.find's
advantage.

Jeremy



Relevant Pages

  • Re: partial / wildcard string match in in and list.index()
    ... > to exact matching. ... There is a regular expression library, aptly called 're', for non-exact ... The standard string methods only do exact searching likely because there ...
    (comp.lang.python)
  • Re: String search vs regexp search
    ... >> The regular expression code has a startup penalty since it has to ... >> searching may be faster than the naive str.find. ... >> the compile, the regular expression may win out. ... looked for constant strings at the start of the regex, ...
    (comp.lang.python)
  • Re: how to split a string using ,fixed character length, variable text delimmiter
    ... a string in encountered that is at least 20 characters long, ... you could try using a regular expression such as this: ... you'd just be searching the text in question for occurrences of the ... out whether any given string has the correct maximum length. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Can I Search Folders using Boolean operands?
    ... With that being the case, searching is a critical function, but I often find that one or two word searches aren't effective and I would like to be able to do Boolean searches. ... Agent Ransack can save the search result to a file, as text, ... you can use regular expression on both the file name part and the find ... torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway Administration scripting examples and an ONLINE version of the 1328 page Scripting Guide: http://www.microsoft.com/technet/scriptcenter/default.mspx. ...
    (microsoft.public.win2000.general)
  • Re: [perl-python] Python documentation moronicities (continued)
    ... > Compile a regular expression pattern into a regular expression object, ... > The expression's behaviour can be modified by specifying a flags ...
    (comp.lang.python)