performance - regex match upto some character -


status updated

Often a situation is where you want to remove For example, a letter before some characters (immediately) , for example, suppose you have a text:

  • does not start with a semicolon or period ,
  • contains many sentences in it,
  • no
  • ends with a period,

    and you Sequencing from the beginning to the nearest semicolon or period Received want. Two strategies came into focus:

    1. / [^;.] * /
    2. /.*? [..] /

      I look at both ways in some of these ways with a little preference of the other strategies, and the code of others. Which is the better way? Is there a clear reason for liking one over the other, or better ways? I feel personally, the efficiency is one side, which is more complex than doing negation something (as with [^] ). But efficiency can also be a good reason to choose one over the other.

      I came up with my answer. In my question two regexes were not really speaking the same thing

      1. If you want to match up on a specific character, use it < P> /.*?

        1. If you want a match just before a certain character (besides) You should use:

          / [^;.] * /

Comments