Compile regex in PHP

后端 未结 5 1608
离开以前
离开以前 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条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-13 04:20

    I'm not positive that you can. If you check out Mastering Regular Expressions, some PHP specific optimization techniques are discussed in Chapter10: PHP. Specifically the use of the S pattern modifier to cause the regex engine to "Study" the regular expression before it applies it. Depending on your pattern and your text, this could give you some speed improvements.

    Edit: you can take a peek at the contents of the book using books.google.com.

提交回复
热议问题