Compile regex in PHP

后端 未结 5 1609
离开以前
离开以前 2020-12-13 03:25

Is there a way in PHP to compile a regular expression, so that it can then be compared to multiple strings without repeating the compilation process? Other major languages

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-13 04:17

    preg regexes can use the uppercase S (study) modifier, which is probably the thing you're looking for.

    http://www.php.net/manual/en/reference.pcre.pattern.modifiers.php

    S

    When a pattern is going to be used several times, it is worth spending more time analyzing it in order to speed up the time taken for matching. If this modifier is set, then this extra analysis is performed. At present, studying a pattern is useful only for non-anchored patterns that do not have a single fixed starting character.

提交回复
热议问题