Loading ...
Sorry, an error occurred while loading the content.

Re: [NTB] Executing a series of commands

Expand Messages
  • Wayne VanWeerthuizen
    ... Oops. That what I get for hurrying to fast. I meant to write: apple{[^ s]*} s{[^ s]*} s{[^ s]*} s{[^ s]*} s{[^ s]*} s Your B version might as good or
    Message 1 of 11 , Jan 12, 2005
    • 0 Attachment
      Alex Plantema wrote to me:
      > Did you mean apple{\B*}\s{\B*}\s{\B*}\s{\B*}\s{\B*}\s ?

      Oops. That what I get for hurrying to fast. I meant to write:

      apple{[^\s]*}\s{[^\s]*}\s{[^\s]*}\s{[^\s]*}\s{[^\s]*}\s

      Your \B version might as good or even better, depending on the
      situation in which it is used.

      > You're right, in a lot of cases it may be better to search
      > for non-spaces between the spaces. This matches the first
      > 5 spaces instead of the last 5 spaces on the line.

      Yes. That is the primary point of not using .*

      Also note: the nonspace versions execute faster than the .*
      version, since the regular expression engine doesn't have to
      "backtrack". With the .* version, the regular expression
      engine attempts to have the first .* match everything to the
      end of the line (it is greedy). But then it has to revise
      that decision, in order for the second .* to have something
      to match. Then it has to revise both of those shorter still,
      so that the third .* can match. By the time it has matched
      the fifth .*, the regular expression engine has wasted a
      significant amount of processor time on extraneous
      calculations.

      On the other hand the nonspace versions (/B* or [^\s]*) are
      direct and to the point, so the search is performed in
      a much more direct and thus efficient manner.

      That is the other major reason why experts frown upon
      the use of .*

      And the more .* are combined in the same expression, the
      less efficient the search gets. It is even possible to
      write a regular expression so horrible, that the search
      would take over a _century_, even with a fast computer
      and a small document.
    Your message has been successfully submitted and would be delivered to recipients shortly.